基于URL的角负载路由

问题描述 投票:0回答:1

我有2套不同的路由,并且根据URL,我需要加载路由和重定向。

export const general_routes: Routes = [
  {
    path: '',
    children: [
        { path: 'login', component: LoginComponent },
        { path:'',redirectTo:'home',pathMatch:'full',canActivate :[AuthGuard]}, 
        { path: 'home', component: WorkbenchhomeComponent, canActivate: [AuthGuard]
        },            
    ]
  }
];

export const tool_routes: Routes = [
  {
    path: '',
    children: [
        { path: 'toolHome', component: ToolSuiteComponent },
        { path:'',redirectTo:'toolHome',pathMatch:'full'}
      ]
  }
];

@NgModule({
  imports: [ RouterModule.forRoot((window.location.href.includes('tool'))?tool_routes:general_routes)], 
  exports: [RouterModule]
})
export class AppRoutingModule {
}

“ RouterModule.forRoot((window.location.href.includes('tool'))”始终评估为true,并且加载了tool_routes。当我尝试不带“工具”的网址访问时,通常不会加载路线并尝试在tool_routes中找到“家”。

nginx angular7 angular7-router
1个回答
0
投票

[我正在尝试相同的操作,但在我的情况下也无法正常工作,然后我使用Angular路由快照来获取页面的url详细信息,并在此基础上给出了路由条件数组。

© www.soinside.com 2019 - 2024. All rights reserved.