Redirect within MapUnknownRoutes in Aurelia

2019-05-10 08:05发布

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条回答
祖国的老花朵
2楼-- · 2019-05-10 08:41

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

查看更多
登录 后发表回答