延迟加载而不为模块添加路由段 [英] Lazy Loading without adding route segment for module

查看:53
本文介绍了延迟加载而不为模块添加路由段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆