[英]Deep paths with app-route element
I'm using app-route component for routing. 我正在使用应用程序路由组件进行路由。
Here is the important part of the code: 这是代码的重要部分:
<app-location route="{{route}}"></app-location>
<app-route
route="{{route}}"
pattern="/:page"
data="{{routeData}}"
tail="{{subroute}}"></app-route>
I would like to improve clarity of my app structure so that settings wouldn't be in a root folder but in a user folder etc. The URL copies the structure of my folders. 我想提高我的应用程序结构的清晰度,以使设置不会出现在根文件夹中,而不会出现在用户文件夹中。URL复制了我的文件夹结构。 Ideally the app-route pattern would be similar to this:
理想情况下,应用程序路由模式应与此类似:
pattern="/{folderpath}/:page" pattern =“ / {folderpath} /:page”
Then I would use obserever that would listen to routeData change, which would receive folderpath and page as parameters. 然后,我将使用Obserever来侦听routeData的更改,该更改将接收folderpath和page作为参数。 After that I would lazy-load the page appropriately:
之后,我会适当地延迟加载页面:
var resolvedPageUrl = this.resolveUrl("/views/" + folderpath + page + '-view.html');
this.importHref(resolvedPageUrl, null, this._showPage404, true);
I know that it would be easily accomplished by removing the app-route element and parsing the route myself, but I wonder if there is an "offical" way to get this behavior using app-route component. 我知道可以通过删除app-route元素并自己解析路由来轻松实现,但是我想知道是否存在使用“ app-route”组件获得此行为的“正式”方法。
Thanks in advance, Jan 预先感谢,扬
The general idea is that you chain routes together. 通常的想法是将路线链接在一起。 So to achieve what you want you effectively, probably would do something like this
因此,要有效地实现您想要的目标,可能会执行以下操作
<app-location route="{{route}}"></app-location>
<app-route
route="{{route}}"
pattern="/:folderpath"
data="{{routeData}}"
tail="{{subRoute}}"></app-route>
--------- Another element perhaps ---------也许是另一个要素
<app-route
route="{{subRoute}}"
pattern="/:page"
data="{{subRouteData}}"></app-route>
Beware, there is a little gotcha with this, in that the "page" app-route
will match regardless of what folder-path actually is, and if you are distributing this in other elements then you might not want it to happen. 当心,这样做有点麻烦,因为“ page”
app-route
将匹配,而不管实际的文件夹路径是什么,并且如果将其分发到其他元素中,则可能不希望它发生。
The solution to this is to extend pattern in the subroute cases - like so 解决方案是在子路由情况下扩展模式-像这样
<app-route
route="{{subRoute}}"
pattern="/reports/:page"
data="{{subRouteData}}"></app-route>
and 和
<app-route
route="{{subRoute}}"
pattern="/appointments/:page"
data="{{subRouteData}}"></app-route>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.