延迟加载而不为模块添加路由段 [英] Lazy Loading without adding route segment for module
问题描述
要在Angular应用中实现延迟加载,我们需要添加模块路由/主页(/public/),然后添加内页路由(/contact-us),如
To implement Lazy Loading in Angular app, we need to add module route / main page (/public/) and then inner page route(/contact-us) like
{ path: 'public', loadChildren: '../public/public.module#PublicModule' }
并在PublicRouting中
and inside PublicRouting
{ path: 'contact-us', component: ContactUsComponent }
现在对于ContactUs组件,我们的网址类似于 http://myappurl/public/contact-us .但是我要实现延迟加载,还需要访问带有 http://myappurl/contact-us 使我的SEO事情按预期工作.我不想将每个页面都作为模块,而我的模块有多个页面
now for ContactUs component we have url like http://myappurl/public/contact-us . But I want to implement Lazy Loading and also need to access page with link like http://myappurl/contact-us so that my SEO things works as expected. I don't want to make each page as module and my modules have multiple pages
推荐答案
如果要实现此目的: http://myappurl/contact-us
在模块路由中用''替换 public
Replace public
with '' in the module routing
{ path: '', loadChildren: '../public/public.module#PublicModule' }
然后什么也不要更改
或:
在模块路由中用"contact-us"替换 public
Replace public
with 'contact-us' in the module routing
{ path: 'contact-us', loadChildren: '../public/public.module#PublicModule' }
,然后在public.module的路由模块中
and then inside the routing module of public.module
{ path: '', component: ContactUsComponent , pathMath:"full" }
这篇关于延迟加载而不为模块添加路由段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!