我正在使用延迟加载。我想使Url除参数外不敏感。
app-routing.module.ts
{
path: 'user/:Id',
loadChildren: '../app/user/user.module#userModule',
}
user-routing.module.ts
const playerRoutes: Routes = [
{
path: '', pathMatch: 'full',
component: userComponent
},
{
path: 'friends',
component: userfriendsComponent
},
]
在userComponent.ts和userfriendsComponent.ts中,将id传递给服务并获取数据。
userComponent.ts
this.activatedRoute.params.subscribe(params => {
this.service.getUserdata(params[['Id']);
});
userfriendsComponent.ts
this.activatedRoute.params.subscribe(params => {
this.service.getUserFriendsdata(params[['Id']);
});
例如id = aBcDeF; 我的路由路径是 http://localhost:4200/user/aBcDeF和 http://localhost:4200/user/aBcDeF/friends
我想使不区分大小写的url(除了id); 我尝试了以下代码,但将整个网址更改为 小写。
app.module.ts
import { DefaultUrlSerializer, UrlTree , UrlSerializer} from
'@angular/router';
export class LowerCaseUrlSerializer extends DefaultUrlSerializer {
parse(url: string): UrlTree {
return super.parse(url.toLowerCase());
}
@NgModule({
imports: [
...
],
declarations: [AppComponent],
providers: [
{
provide: UrlSerializer,
useClass: LowerCaseUrlSerializer
}
],
bootstrap: [AppComponent]
})
}