首页 > 解决方案 > 在 Angular 中使用 Route 导航到特定页面

问题描述

我想使用 Angular 提供的路由显示一个页面,如果 minType = mino 在我的路由文件中,有必要转到路由中声明的另一个组件,这可能吗?

我需要使用 Childs 路线吗?或者在 ts 文件中执行if() ?

谢谢你。

路由

const minRoutes: Routes = [
 {
  path: min/:id/:mineType,
  component: MinComponent,
 }
]

ts.文件

getDataFromRoute() {
 this.route.paramMap.subscribe((params:Params) => {
  this.id = params.get('id');
  this.type = params.get('mineType');
 }
}

标签: angulartypescriptangular-routing

解决方案


我认为你可以使用这条路线:

const minRoutes: Routes = [
 {
  path: min/mino/:id,
  component: AnotherComponent,
 },
 {
  path: min/:mineType/:id,
  component: MinComponent,
 }
]

推荐阅读