当使用名为路由器插座的Angular 2路由器时,我得到了一些奇怪的网址。我知道有一个类似的答案(this one),但我的情况有点不同。如果是那样的问题,我可以解决这个问题。
关键是,我的应用程序中有一个限制区域,一个管理仪表板。当用户进行身份验证时,此管理模块是延迟加载的,因此我有2个路由配置,一个在用户尚未登录时:
export const routing = [
{ path: '', redirectTo: '/adm/(adminoutlet:home)', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{
path: '',
canLoad: [AuthGuard],
loadChildren: './../admin/admin.module#AdminModule'
},
{ path: '**', component: NotFoundComponent },
];
当他已经登录时:
export const adminRouting = [
{
path: 'adm',
canActivateChild: [AuthGuard],
component: AdminComponent,
children: [
{ path: 'home', component: HomeComponent, outlet: "adminoutlet" },
{ path: 'client', component: ClientComponent, outlet: "adminoutlet" },
// etc...
]
},
];
我的管理员html:
<ul>
<li><a [routerLink]="[{outlets: { adminoutlet: ['home']} }]">Home</a></li>
<li><a [routerLink]="[{outlets: { adminoutlet: ['client']} }]">Client</a></li>
<!-- etc... -->
</ul>
<router-outlet name="adminoutlet"></router-outlet>
这给我带来了两个主要问题:
在admin模块父路由器上没有定义/adm
时,我无法正常工作。我更喜欢使用简单的网址,例如:mysite.com/home
而不是mysite.com/adm/home
网址非常奇怪,就像在另一个问题中一样,它是这样的:mysite.com/adm/(adminoutlet:home),我希望它是mysite.com/adm/home
,甚至是更好,就像之前的项目一样,只是一个简单的网址:mysite.com/home
目前它正在运作,但我想解决这些“问题”。
我该怎么做?
我遇到的一个问题是当我删除网址前缀adm
时。由于它是懒惰加载,我不断收到错误:
错误错误:未捕获(在承诺中):错误:无法匹配任何路由。网址细分:'主页'
我认为这与错误有关,但话又说回来,我不知道如何解决这个问题。