angular - 不能在 Angular 路由中使用枚举
问题描述
为避免路径或导航出现拼写错误,在具有许多路径的深度嵌套应用程序中,尝试使用枚举或常量作为路径路径
export enum AppRoutes {
MAIN = 'mainView',
MAIN_SUB = 'mainView/SubView'
}
const registrationRoutes: Routes = [
{
path: AppRoutes.MAIN,
component: ..
children: [
{
path: '',
component: ..
},
{
path: AppRoutes.MAIN_SUB.substr(AppRoutes.MAIN_SUB.indexOf('/') + 1),
component: ..
},
{
path: `${AppRoutes.MAIN_SUB.substr(AppRoutes.MAIN_SUB.indexOf('/') + 1)}`,
component: ..
}
]
}
];
这在没有启用的情况下可以很好地工作ng serve
并编译代码。aot
但是,使用production
代码或aot
启用它总是会导致path
编译器省略 where 属性。
{
path: "",
component: A
children: [{
path: "",
component: sn
}, {
component: Pn
}, {
component: An
}]
}
我曾尝试使用enum
, const
,等static
属性,component
但结果始终相同。
试图找出代码有问题还是AOT行为......
解决方案
推荐阅读
- r - 使用 igraph 和 R 快速找到所有长度为 N 的路径
- sql - 如何在多行上删除特定字符后的部分字符串
- arrays - 如何从powershell对象中提取属性
- ruby-on-rails - Rails.configuration.generators.active_record 在测试期间是如何设置的?
- spring - 弹簧网络套接字 403
- android - 按一次返回按钮停留在同一个片段上,如果按两次,它将返回到上一个片段
- amazon-web-services - 没有 ECS 任务的 CloudWatch 日志,原因是“任务中的基本容器已退出”
- java - 在 Android Java 的硬件键盘上设置 CAPS_LOCK 和 NUM_LOCK
- javascript - 从 Javascript 生成的 HTML 的 Ajax
- excel-formula - 将文本字符串插入 Excel 中另一个文本字符串的特定位置