我希望能够在 Angular 中使用卸载的模块链接路由重定向路径,以便我可以将路径信息保存在配置路由路径的相关模块中。
例如,在app-routes.module.ts
const appRoutes: Routes = [
{ path: 'home', loadChildren: 'app/home/home.module#HomeModule' },
{ path: 'feature', loadChildren: 'app/feature/feature.module#FeatureModule' },
//----- App Root Routing Necessary Safeguards (AppRoutingModule) ----------
{ path: '', redirectTo: '/home', pathMatch: 'full' }, /* '/home' only so I can change the relative route paths in home-routing.module without going back here */
{ path: '**', component: PageNotFoundComponent }
];
例如,在家庭路线中。它还需要处理重定向。(即使来自以前的重定向(
const homeRoutes: Routes = [
{ path: '', redirectTo: '/home/start', pathMatch: 'full' }, /* Placed first since it's a first-match win in config */
{
path: '',
component: HomeComponent,
children: [
{ path: 'start', component: startComponent },
{ path: 'component-two', component: ComponentTwo },
{ path: 'component-three', component: ComponentThree },
]
},
];
当我使用路径/home
时,我能够获得重定向,但当它使用默认的空路径/
时则无法获得重定向。
例如,加载应用程序时的重定向行为(左侧是网址,右侧是重定向(:
/
--->/home
/home
-->/home/start
期望的行为:
/
--->/home/start
/home
-->/home/start
我应该在home-routes.module使用什么配置来达到预期的效果?
重定向到无法实现: https://github.com/angular/angular/issues/10120 (您可以重新打开问题并展示您的案例(也许他们会添加链接重定向((
但是有一些解决方法: https://www.bennadel.com/blog/3600-chaining-absolute-and-local-redirects-with-the-router-in-angular-7-2-13.htm
我现在意识到这个问题有多老了。