考虑我要重写从/register
到/tenant/register
的网址,其中: -
/register
没有实际视图,因为它只能使网址更好。/tenant/register
是实际视图,带有<my-tenant-register>
视图元素。是否可以使用<app-route>
重写网址?因此它可以有一个虚拟路径,并通过某些规则重定向到app-route。
答案 0 :(得分:1)
以PSK为例,我们需要在path-changed
中添加<app-location>
监听器,如下所示: -
<app-location id="location"
route="{{route}}"
url-space-regex="^[[rootPath]]"
on-path-changed="rewritePath">
</app-location>
然后定义rewritePath()
的规则如下: -
/**
* Rewrite path before passing to <app-route>
*/
rewritePath() {
let location = this.$.location;
let path = location.path;
if (path == '/register') {
location.path = '/tenant/register';
}
}
答案 1 :(得分:0)
关于问题的主管,请添加:
<app-location route="{{newRoute}}"></app-location>
自定义元素的顶部,并在您的函数中动态定义新路由:
this.set('newRoute.path', "/tenant/register");// That you really want to go.
this.set
方法将指导您的新目标,就像您按下<a href='/tenant/register'>Tenant/Register </a>