router-outlet - 将 Angular 版本 8 更新到 11 后,应用程序未运行
问题描述
我有一个从 8 到 11 的 Angular 应用程序版本更新。此路由器在更新后无法工作。应用程序运行时显示空白页。编译和浏览器控制台没有错误。如何解决问题?
export const AppRoutes : Routes = [
{ path: 'login', component: LoginPageComponent }
{ path: '', component: MainComponent},
{ path: '', component: MainComponent, children: [
{ path: 'test-one', loadChildren: () => import('./TestOne/TestOne.module').then(m => m.TestOneModule)},
{ path: 'test-two', loadChildren: () => import('./TestTwo/TestTwo.module').then(m => m.TestTwoModule), canActivate: [AuthGuard], runGuardsAndResolvers: 'always'}
]},
{ path: ':pageslug', component : MainComponent },
{ path: '**', component : MainComponent }
];
解决方案
Angular 11 中关于路由器的一些重大更改如下:
router: * RouterModule.forRoot 中选项的 initialNavigation 属性不再支持 legacy_disabled、legacy_enabled、true 或 false 作为有效值。legacy_enabled(旧默认值)改为 enabledNonBlocking enabled 已被弃用为 RouterModule.forRoot initialNavigation 选项的有效值。已引入 enabledBlocking 来替换它 router: preserveQueryParams 已被删除,使用 queryParamsHandling=”preserve” 代替 router: 如果您正在访问 RouterLink 的 queryParams、fragment 或 queryParamsHandling 值,您可能需要放宽输入以接受 undefined 和 null。(#39151)
请参阅: https ://medium.com/swlh/angular-11-in-depth-9a7372b4a600
推荐阅读
- uber-api - 使用 Uber API 预订行程
- javascript - 将 setInterval() 绑定到 jQuery 元素
- vue-cli-3 - 在 Mac 上找不到 vue 命令
- reactjs - 如何在反应和春季启动的axios发布请求中添加csrf令牌?
- php - 我正在尝试使用 php 代码连接到 mysql 数据库,但它给了我这个错误(见下文)
- react-native - react-native Intent SEND 与 react-native-navigation [v2]
- javascript - Javascript Nested For Loop 在返回数组时不更新数组
- python - 如何将 pytorch 张量转换为 numpy 数组?
- apache-kafka - 如何使用 Kafka 实现事件溯源?
- c - %PRId 和 %d 格式字符有什么区别?