【问题标题】:Wildcard routes in aurelia not working?aurelia中的通配符路线不起作用?
【发布时间】:2018-03-15 00:06:38
【问题描述】:

我正在尝试在使用 aurelia 的现有应用程序中包含新的路由配置。我想在两者之间匹配一些 URL 路径,所以我想到了使用通配符。网址如下所示:

http://localhost:4703/*path/somepage

所以当我在互联网上搜索时,我发现了以下问题,即 aurelia 无法使用通配符匹配 URL 之间的任何内容

https://github.com/aurelia/router/issues/297

我查看了 aurelia router 的源代码以更好地理解,我在下面找到了

https://github.com/aurelia/router/blob/master/src/navigation-instruction.js

行号:141

  getWildCardName(): string {
    let wildcardIndex = this.config.route.lastIndexOf('*');
    return this.config.route.substr(wildcardIndex + 1);
  }

还有其他方法可以实现吗?

【问题讨论】:

    标签: aurelia


    【解决方案1】:

    来自aurelia router documentation

    通配符路由用于匹配路径的“其余部分”(即:files/*path 匹配 files/new/doc 或 files/temp)。在段之后带有 URL 其余部分的对象被设置为路径属性,并作为参数传递给 activate()。

    这样你就可以将路由的“其余部分”作为单个参数匹配并自己处理

    你可以定义一个方法来处理未知路由,并检查它们是否以你想要的方式结束并适当地处理

    【讨论】:

      猜你喜欢
      • 2017-01-25
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 2020-01-08
      • 1970-01-01
      • 2020-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多