Nik*_*ita 7 import circular-dependency typescript angular
路线段已移至常量。下面的代码是简化的,但在项目中大约有 5 个惰性模块,每个模块有大约 20 个路由和段,通常在服务和组件中router.navigate
用作对象中的字符串键(某些组件的图像:)assets/images/${urlSegment}.jpg
。为此,段已移至常量。
路由.module.ts
export const PATIENT_URL_SEGMENTS = {
TOOLS: 'tools',
INDEX: 'index',
};
const routes = [
{ path: PATIENT_URL_SEGMENTS.TOOLS, component: ToolsComponent }
{ path: `${PATIENT_URL_SEGMENTS.TOOLS}/:${PATIENT_URL_SEGMENTS.INDEX}`, component: ToolDetailsComponent }]
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: []
})
export class PatientRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
RoutingModule
用于延迟加载模块。如果我URL_SEGMENTS
从单独的文件导入,在浏览器控制台中我会看到 error Can not read split of undefined
。但是,如果如上面的示例中那样在适当的位置声明了常量,则一切正常。
每个导入的组件都会发出一个警告PATIENT_URL_SEGMENTS
,因为同时这些组件已导入到路由模块中。事实上没有错误,但我想删除组件 import 时的警告PATIENT_URL_SEGMENTS
。
你知道如何实现这一目标吗?也许可以将常量声明移动到单独的文件?
归档时间: |
|
查看次数: |
2088 次 |
最近记录: |