博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Angular] N things you might don't know about Angular Route
阅读量:5224 次
发布时间:2019-06-14

本文共 1540 字,大约阅读时间需要 5 分钟。

Prevent Partail Page display: By using Resolver:

@Injectable()export class MovieResolver implements Resolve
{ constructor(private movieService: MovieService) { } resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable
{ const id = route.paramMap.get('id'); return this.movieService.getMovie(+id); }}
providers: [   MovieService,   MovieResolver]
{   path: 'movies/:id',   resolve: { movie: MovieResolver },   component: MovieDetailComponent},
ngOnInit(): void {   this.movie = this.route.snapshot.data['movie'];}

 

Display Loading spinner when switching page:

constructor(private router: Router) {   router.events.subscribe((routerEvent: Event) => {      this.checkRouterEvent(routerEvent);   });}checkRouterEvent(routerEvent: Event): void {   if (routerEvent instanceof NavigationStart) {      this.loading = true;   }   if (routerEvent instanceof NavigationEnd ||       routerEvent instanceof NavigationCancel ||       routerEvent instanceof NavigationError) {      this.loading = false;   }}

 

Enable route debugging:

RouterModule.forRoot([  {    path: '', component: ShellComponent,    children: [      { path: 'welcome', component: WelcomeComponent },      { path: 'movies', component: MovieListComponent },      { path: '', redirectTo: 'welcome', pathMatch: 'full' }    ]  },  { path: 'login', component: LoginComponent },  { path: '**', component: PageNotFoundComponent }], { enableTracing: true })

 

 

转载于:https://www.cnblogs.com/Answer1215/p/9000731.html

你可能感兴趣的文章
Silverlight 的菜单控件。(不是 Toolkit的)
查看>>
:hover 鼠标同时触发两个元素变化
查看>>
go语言学习十三 - 相等性
查看>>
Idea 提交代码到码云(提交到github也大同小异)
查看>>
c#连接excel2007未安装ISAM解决
查看>>
Mono 异步加载数据更新主线程
查看>>
初识lua
查看>>
我是插件狂人,jDuang,jValidator,jModal,jGallery
查看>>
张季跃 201771010139《面向对象程序设计(java)》第四周学习总结
查看>>
如何解除循环引用
查看>>
android中fragment的使用及与activity之间的通信
查看>>
字典【Tire 模板】
查看>>
jquery的contains方法
查看>>
python3--算法基础:二分查找/折半查找
查看>>
Perl IO:随机读写文件
查看>>
Perl IO:IO重定向
查看>>
转:基于用户投票的排名算法系列
查看>>
WSDL 详解
查看>>
[转]ASP数组全集,多维数组和一维数组
查看>>
C# winform DataGridView 常见属性
查看>>