首页 > 解决方案 > 如何路由具有多个段的 url 部分

问题描述

我需要根据前缀将 url 传递给不同的后端。例如下面的网址

http://mysite/backend1/rest/of/url

需要使用 :backend 和 :restOfUrl 标记路由到“BackendComponent”,其中 :backend = 'backend1' 和 :restOfUrl = 'rest/of/url'

我试过了

 {
    path: ':backend/:restofurl',
    component: BackendComponent
 }

但没有找到路线。我也试过简单

path: 'Backend1/:restofurl'

但它仅在 :restofurl 没有正斜杠(即只有一个段)时才有效

这在Angular 2+中可能吗?如果是这样,如何?

标签: angularangular2-routing

解决方案


类似的东西

{
    path: 'Backend1',
    component: BackendComponent,
    children: [
        { path: '**', component: BackendComponent }
    ]
}

推荐阅读