角度路由策略



我看到 2 种方法:

1( 将根模块定义为单一事实来源,其中处理所有路由路径,例如

const routes = [
{path: 'home', component: HomeComponent}  
children: [...]
]

仅供使用:

RouterModule.forRoot(routes)

2(

const routes = [
{path: 'home', component: HomeModule}  
]

然后在主页模块中

const homeRoutes = [
...
]

和使用

RouterModule.forChild(homeRoutes)

你使用什么策略?

如果您的应用程序很小并且会保持较小(3-6 个视图(,我建议您使用选项 1

但是,如果您有多个子模块(想想带有IventoryModule和UserMangementModule的销售应用程序(,那么选项2。这是因为您希望路由到本地到与其相关的模块(特别是如果有一天您可能会单独打包这些模块(。

最新更新