-1

我试图在我的当前页面上弹出一个垫子对话框,但是当我单击按钮弹出对话框时,对话框出现但随后将我导航到我的默认路线而不是停留在同一页面上。

这是我的router模块:

const routes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'login', component: LoginComponent },
  { path: 'signup', component: SignupComponent },
  { path: 'main-nav', component: MainNavComponent, children: [
    { path: 'create-service', component: CreateServiceComponent },
    { path: 'dashboard', component: DashboardComponent },
    { path: 'designations', component: DesignationsComponent, children: [
      { path: 'dialog', component: AddDesignationsComponent }
    ] },
  ] }
];

我试图通过单击按钮弹出AddDesignationsComponent下方DesignationsComponent,但它会弹出并将页面导航到HomeComponent. 我想我的错误来自我的路由模式,但我似乎无法弄清楚。

我哪里会出错。谢谢。

4

2 回答 2

0

路由配置的顺序很重要。路由器接受与导航请求路径匹配的第一个路由。确保最后列出了空路径路由 (HomeComponent)。

从文档:

配置中路由的顺序很重要,这是设计使然。路由器在匹配路由时使用先匹配获胜策略,因此更具体的路由应该放在不太具体的路由之上。

于 2019-07-14T08:13:20.667 回答
0

抱歉,是我的错。一起使用点击事件和routerLink。

mat-dialog 弹出并将页面导航回应用程序的默认路由

于 2019-07-14T21:03:04.347 回答