Skip to content

makeCRUDRoutes

Overview

Generate CRUD routes for a given app and model.

Call this once during application setup and register the two records it returns. Besides building them, it starts watching for a change of authenticated user. When one happens while the application sits on one of these routes, it reruns the same guard chain against that route and redirects if the new user may not use it. The guard chain otherwise runs only on route entry, so without this the previous user's view stays on screen at a URL the new user cannot use.

Signature

makeCRUDRoutes(params)

Parameters

NameTypeRequiredDescription
paramsobjectyesThe parameters.

params Properties

NameTypeRequiredDefaultDescription
actionRedirectanyThe route to redirect if model/action not found.
authRedirectstringThe route to redirect to if the user is not authenticated.
componentanyThe component to use for the routes.
groupsstring[]The groups required to access the views.
groupsRedirectanyThe route to redirect to if the user is not in the required groups.
pathPrefixstringThe prefix to add to the path.
piniaPiniaThe Pinia instance.
routerRouterThe Vue router instance.
vueAppAppThe Vue app instance.

Returns

RouteLocationNormalizedGeneric[]

The generated routes.

Examples

js
import { createRouter, createWebHistory } from 'vue-router';
import ActionView from '@/views/ActionView.vue';
import { makeCRUDRoutes } from '@vueda/router/makeCrud.js';

const router = createRouter({ history: createWebHistory(), routes: [] });

// In your app setup (after createApp):
router.addRoute(...makeCRUDRoutes({
    component: ActionView,
    vueApp: app,
    router,
    pinia,
    authRedirect: { name: 'login' },
    actionRedirect: { name: 'not-found' },
}));

Source

client/lib/router/makeCrud.js:95

Documents matching: server v3.0.0a1.post1client v3.0.0-alpha.2