问题
I want bad routes to navigate to the root route. I've added a mapUnknownRoutes
configuration on my router.
config.mapUnknownRoutes((inst) => inst.config.moduleId = 'home');
But this leaves the route untouched. For example, #/fakeRoute
routes to home. Ideally, I would like a behavior similar to returning { redirect: '#/' }
, which cancels navigation and creates a new navigation to the route '#/'
. Is this a feature?
回答1:
The mapUnknownRoutes
method also accepts a RouteConfig object so you can just directly specify your redirect there:
config.mapUnknownRoutes({ redirect: '#/' });
See the complete signature of the method on github
来源:https://stackoverflow.com/questions/33280224/redirect-within-mapunknownroutes-in-aurelia