[英]Polymer app-route: multiple routes to same page?
Is there a built-in method for routing multiple possible links to the same "page"? 是否有用于将多个可能的链接路由到同一“页面”的内置方法?
For example, I have a '/' route that loads a landing page by binding the active attribute of that route to a property named landing-active, which is being observed. 例如,我有一个'/'路由,它通过将该路由的active属性绑定到一个名为着陆活动的属性来加载着陆页,该属性正在被观察。 The most straightforwards way I can think of to allow converging routes is to create another app-route element for the new route, and bind its active attribute to the same landing-active property as the '/' route.
我想到的最简单的方法是允许收敛的路由是为新路由创建另一个app-route元素,并将其active属性绑定到与“ /”路由相同的着陆活动属性。
Is there a better/different way of handling this, or should I stick with my method? 是否有更好/不同的方式来处理此问题,还是应该坚持我的方法?
Edit : I tried my method out, and it doesn't work. 编辑 :我尝试了我的方法,它不起作用。 Here's my original route:
这是我的原始路线:
<app-route
id='landing-route'
route='{{route}}'
pattern='/'
active='{{landing-active}}'>
</app-route>
If I then add an alternate route by simply changing the pattern and id, then the '/' route no longer works. 如果随后通过简单地更改模式和ID添加备用路由,则'/'路由将不再起作用。 Changing the active binding on the new route fixes this issue, but also no longer allows it to rout as intended.
更改新路线上的活动绑定可解决此问题,但也不再允许其按预期溃败。 So my conclusion is that I can't bind the same property to the active attribute of two separate app-route elements, so my routing method doesn't work.
因此,我的结论是,我无法将同一属性绑定到两个单独的应用程序路由元素的active属性,因此我的路由方法不起作用。
What alternatives do I have? 我有什么选择?
Option 1: Use two separate active
variables for your two <app-route>
s, and test for either variable (eg, with a computed binding / property ). 选项1:为两个
<app-route>
使用两个单独的active
变量,并测试其中一个变量(例如,使用计算的绑定 / 属性 )。
Option 2: Use a different router component. 选项2:使用其他路由器组件。
<nebula-routing>
might be the best option IMO, given that it has a similar API to <app-route>
and supports regular expression in the route patterns. 鉴于
<nebula-routing>
具有与<app-route>
类似的API并支持路由模式中的正则表达式,可能是IMO的最佳选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.