是否可以使用 <app-route> 重写 URL?

Is it possible to rewrite URL using <app-route>?

考虑我想将 URL 从 /register 重写为 /tenant/register,其中:-

是否可以使用 <app-route> 重写 URL?这样它就可以有一个虚拟路径并根据某些规则相应地重定向到应用程序路由。

关于你的问题,添加:

<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>

以PSK为例,我们需要在<app-location>中添加一个path-changed监听器如下:-

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