【发布时间】:2017-01-30 16:00:31
【问题描述】:
如何忽略子路由中的括号。这是我的代码
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { ShareComponent } from './share.component';
@NgModule({
imports: [
RouterModule.forChild([
{ path: 'share/list/:id/:title', component: ShareComponent },
{ path: 'share/list/:id', component: ShareComponent },
])
]
})
export class ShareRoutingModule { }
只要 id 或 title 值中没有括号,它就可以正常工作。
如果有人在 id 或 title 值中输入括号,因为它们是动态的并且任何人都可以输入任何值,我该如何处理。
如果您需要更多详细信息,请询问我。谢谢
【问题讨论】:
-
您可以提供自定义的 UrlSerializer。括号用于辅助路由,不能忽略。 angular.io/docs/ts/latest/api/router/index/…
-
@GünterZöchbauer 你能多解释一下我该怎么做吗,我看到了你提供的链接,但看不懂。谢谢
-
对不起,我自己还没用过。如果您提供自定义序列化程序,则使用此序列化程序而不是 Angular 本身提供的序列化程序。您可以将
DefaultUrlSerializer作为模板。
标签: angular routing angular2-routing