简体   繁体   English

奥雷利亚中的通配符路由不起作用?

[英]Wildcard routes in aurelia not working?

I am trying to include a new routing configuration in an existing application which uses aurelia. 我试图在使用aurelia的现有应用程序中包括新的路由配置。 I want to match some URL path in between, so I thought of using wildcard. 我想在两者之间匹配一些URL路径,所以我想到了使用通配符。 The URL looks like below: 该URL如下所示:

http://localhost:4703/ *path/somepage http:// localhost:4703 / *路径/某页

So when I searched in internet I found the below issue, which says aurelia won't be able to match anything in between a URL by using wildcard 因此,当我在互联网上搜索时,发现了以下问题,即aurelia无法使用通配符在URL之间匹配任何内容

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

I had a look into the source code of aurelia router to have a better understanding and I found below 我查看了aurelia路由器的源代码以更好地了解,我在下面找到了

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

Line No: 141 行号:141

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

Is there any other way I can achieve this? 我还有其他方法可以实现这一目标吗?

From the aurelia router documentation : aurelia路由器文档中

Wildcard routes are used to match the "rest" of a path (ie: files/*path matches files/new/doc or files/temp). 通配符路由用于匹配路径的“其余”(即:files / * path匹配files / new / doc或files / temp)。 An object with the rest of the URL after the segment is set as the path property and passed as a parameter to activate() as well. 将该段之后具有URL其余部分的对象设置为path属性,并将其作为参数传递给activate()。

so you can match the "rest" of the route as a single parameter and deal with it yourself 因此您可以将路线的“其余”作为单个参数进行匹配并自己进行处理

You can although define a method to deal with unknown routes and check if they end with what you want and handle appropriately 尽管可以定义处理未知路由的方法,并检查它们是否以所需的结尾并适当地进行处理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM