-
-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dynamically add routes #117
Comments
Basic example (load routes when requested): const route = {
path: '/admin',
children: [], // place for lazy routes
async action(context) {
const routes = await import('./admin/routes.js'); // load routes asynchronously
context.route.children = routes; // dynamically add routes
delete context.route.action; // execute action method only once
return context.next(); // go to just loaded routes
}
} Also you can dynamically add new routes at any time: routes.push(newRoute) Your routes are just plain javascript object and arrays, you can interact with them as you like. Would you describe your use case more or provide examples, why do you want to modify context? |
Thanks a lot, it works perfectly, see the full code at https://github.com/FredericHeem/starhackit/blob/master/client/src/app/router.js |
Would it be possible to dynamically add routes found in a chunk loaded through
import
?When a route is loaded asynchronously, the router context passed is a copy so the original context cannot be modified at the moment.
The text was updated successfully, but these errors were encountered: