export const routes: Routes = [
{
path: '',
resolve: { mockData: MockApiResolver },
loadChildren: () => import('./shared-components/initilisation/initilisation.module').then(m => m.InitilisationModule)
},
{ path: 'error', component: ErrorComponent, data: { title: 'Generic error' } },
{ path: '**', component: ErrorComponent, data: { title: '404 not found' } }
];
提供了数据,并加载了启动的孩子。该模块也有孩子:
const routes: Routes = [
{
path: "",
component: InitilisationComponent,
children: [
{
path: 'options',
loadChildren: () => import('../../view-components/options/options.module').then(m => m.OptionsModule)
},
]
}
];
这将创建路由'/options',然后在initilisation.com上导航到它:
constructor() {
this.route.parent?.data.subscribe(data => {
const response = data['mockData'];
if (response) {
console.log(response)
this.router.navigate([response.path]).then(() => {
// Handle successful navigation if needed
console.log("route successful")
}).catch(err => {
console.error('Navigation error:', err);
});
}
});
}
该路由在URL中工作,但该组件不加载。我似乎不知道为什么?任何帮助都值得注意的是,这是该应用程序的stackblitz。 我的想法是,这条路线不是及时创建的,但是我在导航周围放了一个超时,但没有做任何事情。 这个想法是从BE获得一条路线,并导航到App初始化的该路线。
不应包裹在任何条件语句中,显示/隐藏会破坏DOM元素并可能弄乱导航。
router-outlet