zoukankan      html  css  js  c++  java
  • angular 守卫路由

    import { NgModule } from '@angular/core';
    import { Routes, RouterModule } from '@angular/router';
    import { HomeComponent } from './home/home.component';
    import { ProductComponent } from './product/product.component';
    import { Code404Component } from './code404/code404.component';
    import { ProductDescComponent } from './product-desc/product-desc.component';
    import { SellerInfoComponent } from './seller-info/seller-info.component';
    import { ChatComponent } from './chat/chat.component';
    import { LoginGuard } from './guard/login.guard';
    import { UnsacedGuard } from './guard/unsaced.guard';
    
    const routes: Routes = [
      {
        path: '',
        redirectTo: '/home',
        pathMatch: 'full'
      },
      {
        path: 'chat',
        component: ChatComponent,
        outlet: 'aux'
      },
      {
        path: 'home',
        component: HomeComponent
      },
      {
        path: 'product/:id',
        component: ProductComponent,
        children: [
          { path: '', component: ProductDescComponent },
          { path: 'seller/:id', component: SellerInfoComponent }
        ],
        canActivate: [LoginGuard],
        canDeactivate: [UnsacedGuard]
      }
      ,
      {
        path: '**',
        component: Code404Component
      }
    ];
    
    @NgModule({
      imports: [RouterModule.forRoot(routes)],
      exports: [RouterModule],
      providers: [LoginGuard, UnsacedGuard]
    })
    export class AppRoutingModule { }
  • 相关阅读:
    Algs4-2.1.23纸牌排序
    python字符串加颜色区别
    python学习之字典
    python学习之while语句
    python学习之字符串变量
    python学习之列表语法
    python简单实现用户表单登录
    python学习之安装模块
    python学习之认识字符串
    python学习之for语句
  • 原文地址:https://www.cnblogs.com/chenyishi/p/8903994.html
Copyright © 2011-2022 走看看