本文介绍了在Aurelia中的MapUnknownRoutes中重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望不良路线导航到根路线.我在路由器上添加了mapUnknownRoutes配置.

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');

但这使路线保持不变.例如,#/fakeRoute路由到家.理想情况下,我想要一种类似于返回{ redirect: '#/' }的行为,该行为将取消导航并创建对路径'#/'的新导航.这是功能吗?

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?

推荐答案

mapUnknownRoutes方法还接受 RouteConfig对象,因此您可以直接在此处指定重定向:

The mapUnknownRoutes method also accepts a RouteConfig object so you can just directly specify your redirect there:

config.mapUnknownRoutes({ redirect: '#/' });

请参见 github

这篇关于在Aurelia中的MapUnknownRoutes中重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 20:42