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
| Name | Type | Required | Description |
|---|---|---|---|
| params | object | yes | The parameters. |
params Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| actionRedirect | any | The route to redirect if model/action not found. | ||
| authRedirect | string | The route to redirect to if the user is not authenticated. | ||
| component | any | The component to use for the routes. | ||
| groups | string[] | The groups required to access the views. | ||
| groupsRedirect | any | The route to redirect to if the user is not in the required groups. | ||
| pathPrefix | string | The prefix to add to the path. | ||
| pinia | Pinia | The Pinia instance. | ||
| router | Router | The Vue router instance. | ||
| vueApp | App | The 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