路由

2017-12-02  本文已影响0人  Yagami_

这里主要详细说一下路由注册后的使用

之前说过注册路由 为了方便讲这里还是再上一次代码

先在项目根目录/src/app/app.module.ts里定义路由

const routeConfig: Routes = [

{path: 'space', component: SpaceComponent}

]

在@NgModule中imports里添加 RouterModule.forRoot(routeConfig)

a标签跳转时可以使用 [routerLink]="['/space']" 进行跳转 

带参数模式[routerLink]="['/space',userId]"

这里再说一下子路由模式

const routeConfig: Routes = [

{path: 'product', component:ProductComponent ,

children:[ {path:'',component:ProductdescComponent},{path:'xxx/:id',component:SellerComponent} ]

}

]

举个引用场景 商品列表点击查询商品详情  (子路由是./)子路由是路由里面套的路由可以无限嵌套    [routerLink]="./xxxx"

辅助路由和路由守卫由于没用到 暂时不更新。

                                                                                                                                                                                                                               2017.12.2 1:05:00

上一篇 下一篇

猜你喜欢

热点阅读