【发布时间】:2016-10-27 23:39:09
【问题描述】:
我无法理解当前的问题,即单击 routerlink 时无法加载新页面。
我已经为链接尝试了许多不同的结构,但无论我将其更改为控制台中的错误提示
VM39436:48 例外:未捕获(承诺中):错误:无法匹配任何 路线。 URL 段:“流”
我使用模板布局,然后使我的页面成为这些布局的子级。一种布局是安全的,一种布局是公开的。
在 app.routing.ts 中
const APP_ROUTES: Routes = [
{
path: '',
redirectTo: 'stream',
pathMatch: 'full',
},
{
path: 'profile',
component: SecureLayoutComponent,
data: {
title: 'Secure Views'
},
children: [
{
path: 'Profile',
loadChildren: 'profile/profile.module#ProfileModule'
}
]
},
{
path: '',
component: PublicLayoutComponent,
data: {
title: 'Public Views'
},
children: [
{
path: 'stream',
loadChildren: 'stream/stream.module#StreamModule',
}
]
}
];
现在我有一个用于配置文件的文件夹和一个用于流的文件夹。
所以当你移动到流目录时,这是 stream-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes,
RouterModule } from '@angular/router';
import { StreamComponent } from './stream.component';
const routes: Routes = [
{
path: '',
component: StreamComponent,
data: {
title: 'Stream'
}
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class StreamRoutingModule {}
这是profile-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes,
RouterModule } from '@angular/router';
import { ProfileComponent } from './profile.component';
export const routes: Routes = [
{
path: '',
data: {
title: 'Secure Pages'
},
children: [
{
path: 'profile',
component: ProfileComponent,
data: {
title: 'Profile Page'
}
}
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class ProfileRoutingModule {}
因此,当应用程序呈现时,它可以正常加载。但是当我尝试点击时,
<a class="nav-link" routerLinkActive="active" [routerLink]="['../profile/profile']">Profile</a>
或者
<a class="nav-link" routerLinkActive="active" [routerLink]="['../profile']">Profile</a>
或
<a class="nav-link" routerLinkActive="active" [routerLink]="['/profile']">Profile</a>
我得到了上面提到的错误,
所以从/目录
/app.routing.ts
/stream/stream.component.ts & stream-routing.module.ts
/profile/profile.component.ts & profile-routing.module.ts // 不能从公共布局访问这个。
【问题讨论】:
-
我没有看到任何带有
path: 'stream'的路线 -
查看 app.routing 和 stream-routing.module 它工作正常。这是我无法上班的个人资料溃败。但是,当流作为主页加载并且我单击链接转到配置文件路由时,错误提到了流。这真的让我很困惑。从昨天开始我就一直坚持这个问题,这就是我发帖寻求帮助的原因。我对这个很迷茫。
-
您有 2 条路径,路径为
''(第一个重定向路径和PublicLayoutComponent)。目的是什么?
标签: angular typescript mean-stack