【发布时间】:2021-10-14 15:55:23
【问题描述】:
我很难找到上班的路线。我正在使用不会导航到路线的 RouterLink。我的 app.routing 有
const routes: Routes = [
{
path: '',
redirectTo: '/',
pathMatch: 'full'
},
{
path: '',
component: LayoutComponent,
loadChildren: () => import('./views/main/main.module').then( m => m.MainModule )
}
];
mainModule 有以下内容
const routes: Routes = [
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},
{
path: 'search',
component: SearchFormComponent,
loadChildren: () => import('../../views/search/search.module').then( m => m.SearchModule )
},
{
path: '**',
redirectTo: '/home',
pathMatch: 'full'
}
];
mainModule 声明并导出 LayoutComponent
在 LayoutComponent.html 中
<a class="nav-link" [routerLink]="'/search'">
Search
</a>
但是当我在 UI 中点击搜索时,路由并没有转到搜索组件。它停留在 Home 组件上。请帮忙 - 我哪里出错了?
【问题讨论】:
-
这能回答你的问题吗? Angular 8 router not redirecting to routes
-
没有。订购路线不是问题。我只有两条路线。为什么找不到“搜索”路线
-
你的第一条路由是
path: '',你的第二条路由是path: 'search',Angular路由器正在寻找你的第一条路径而不是去搜索。 -
@Malcor 当我的 routerLink 有 '/serach' 时,它如何找到'' 路由?无论如何,我尝试将''路线放在最后,但我仍然遇到同样的问题
标签: angular