我看到2种方法:
1)将根模块定义为单个真实来源,例如,在其中处理所有路由路径的
const routes = [
{path: 'home', component: HomeComponent}
children: [...]
]
仅使用:
RouterModule.forRoot(routes)
2)
const routes = [
{path: 'home', component: HomeModule}
]
然后在HomeModule中
const homeRoutes = [
...
]
并使用
RouterModule.forChild(homeRoutes)
您使用什么策略?
答案 0 :(得分:0)
如果您的应用程序较小并且会保持较小(3-6次浏览),我建议您使用选项1 。
但是,如果您有多个子模块(认为带有IventoryModule和UserMangementModule的销售应用),则选项2 。那是因为您希望本地路由到与其相关的模块(特别是如果有一天您可能会单独打包这些模块)。