如何为自定义网址使用路由路径

时间:2019-06-17 10:53:07

标签: angular routing

如何将下面的浏览器URL写入routing.module路径。我尝试了以下路径:"disciplines:disciplineId:&disciplineView",,但无法访问。

浏览器URL http://localhost:4200/xxx/disciplines?disciplineId=12975&disciplineView=create

TS路由

{
    path: "disciplines:disciplineId:&disciplineView",
    component: DisciplinesComponent,
    data: {
      title: 'Disciplines',
      breadcrumb: [
        {
          label: 'disciplines',
          url: '/disciplines'
        },
        {
          label: 'page {{customText}}',
          url: ''
        }
      ]
    },
  }

1 个答案:

答案 0 :(得分:0)

在路由模块中,您仅需要指定主网址(而不是queryParams),就像这样:

 {
    path: "disciplines", component: DisciplinesComponent,
 }

例如,当您想使用学科ID = 12975&disciplinelineView = create时,必须指定如下所示的queryParams:

1-具有routerLink:

 <a [routerLink]="['/disciplines']" [queryParams]="{disciplineId: 12975,disciplineView: 'create' }"

2-使用导航方法:

this.router.navigate(['disciplines'], {queryParams: {
  disciplineId: 12975, disciplineView: 'create'
 }
})