Benefit to use child router is Angualr 2 then can lazy load the component on demand.

Define a child router by adding three dots `/characters/...`:

@RouteConfig([
{ path: '/characters/...', name: 'Characters', component: CharactersComponent, useAsDefault: true },
{ path: '/vehicles/...', name: 'Vehicles', component: VehiclesComponent }
])

So both `characters` and `vehicles` component container child router.

Then in each component, we define its child rotuer

import { Component } from 'angular2/core';
import { RouteConfig, ROUTER_DIRECTIVES } from 'angular2/router'; import { CharacterComponent } from './character.component';
import { CharacterListComponent } from './character-list.component';
import { CharacterService } from './character.service'; @Component({
selector: 'story-characters-root',
template: `
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{ path: '/', name: 'Characters', component: CharacterListComponent, useAsDefault: true },
{ path: '/:id', name: 'Character', component: CharacterComponent }
])
export class CharactersComponent { }
import { Component, OnInit } from 'angular2/core';
import { RouteConfig, ROUTER_DIRECTIVES } from 'angular2/router'; import { VehicleListComponent } from './vehicle-list.component';
import { VehicleComponent } from './vehicle.component';
import { VehicleService } from './vehicle.service'; @Component({
selector: 'story-vehicles-root',
template: `
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES],
providers: [VehicleService]
})
@RouteConfig([
{ path: '/', name: 'Vehicles', component: VehicleListComponent, useAsDefault: true },
{ path: '/:id', name: 'Vehicle', component: VehicleComponent }
])
export class VehiclesComponent { }

----------------

The list component, set routerLink:

<ul class="characters">
<li *ngFor="#character of characters | async">
<a href="" [routerLink]="['Character', {id: character.id}]">
{{character.id}}. {{character.name}}
</a>
</li>
</ul>

[Angular 2] Child Router的更多相关文章

  1. Angular.js之Router学习笔记

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. angular 的ui.router 定义不同的state 对应相同的url

    Angular UI Router: Different states with same URL? The landing page of my app has two states: home-p ...

  3. http://angular.github.io/router/

    Angular New Router Guide Configuring the Router- This guide shows the many ways to map URLs to compo ...

  4. [Angular] Auxiliary named router outlets

    Define a auxilliary router: export const ROUTES: Routes = [ { path: 'folder/:name', component: MailF ...

  5. [Angular] Subscribing to router events

    In our root component, one thing we can do is subscribe to Router events, and do something related t ...

  6. [Angular2 Router] Build Angular 2 Navigation with routerLink

    Angular 2 navigation is configured using the routerLink directive. The routerLink directive behaves ...

  7. [转]Angular: Hide Navbar Menu from Login page

    本文转自:https://loiane.com/2017/08/angular-hide-navbar-login-page/ In this article we will learn two ap ...

  8. AngularJS 使用 UI Router 实现表单向导

    Today we will be using AngularJS and the great UI Router and the Angular ngAnimate module to create ...

  9. [Angular2 Router] Auxiliary Routes bit by bit

    Article Github Auxiliary Routes is is little bit hard to understand. Here is demo, link You can see ...

随机推荐

  1. asp.net 读取sql存储过程返回值

    关于Exec返回值的问题有很多,在这做个简要的总结. 读查询语句示例:    Declare @count int     select @Count 要点:                      ...

  2. iOS9中将图片保存到照片中的某个相册的方法说明

    iOS9中将图片保存到照片中的某个相册的方法说明 在App中很经常遇到的就是用户点击某张图片后将图片保存到本地,下面介绍下iOS中保存图片的一些东西 1.首先,在iOS中把图片保存到系统照片是比较简单 ...

  3. 【COGS1049】天空中的繁星

    [题目背景] 第二届『Citric』杯NOIP提高组模拟赛 第二题 [题目描述] Lemon最近买了一台数码相机.某天Lemon很无聊,于是对着夜空拍了一张照片,然后把照片导入了电脑.Lemon想依靠 ...

  4. CMake----if与option使用小记

    在CMake中if语法比较简单,if后面括号中的参数随着CMake版本的推进,在else和endif中也可以不用写了. if(address) else() endif() 对于if语法,比较常用的就 ...

  5. date命令详解与练习

    date : 用来打印或设置系统日期和时间. 它在linux shell编程中经常会用到.比如每天生成随日期变化的档案名,尤其在银行业务中每天都会生成流水文件.eg:datefile=$(date & ...

  6. javascript 中的nextSibling和previousSibling使用注意事项

    JavaScript中的nextSibling和previousSibling和作用类似于jquery的next()和prev(),都是获取下一个/上一个同胞元素,如果下一个同级节点不存在,则此属性返 ...

  7. 纯js制作遮罩层对话框 -- g皓皓

    //本文支持js在线工具测试.转载请注明出处. <htmlxmlns="http://www.w3.org/1999/xhtml"> <head> < ...

  8. os mac apache+php+mysql环境配置

    1.启用系统自带的apache 服务 打开终端(terminal) #sudo apachectl start #sudo vi /etc/apache2/httpd.conf 修改 LoadModu ...

  9. mysql存储过程的权限 definer

    mysql中用户对存储过程的权限有: ALTER ROUTINE 编辑或删除存储过程 CREATE ROUTINE 创建存储过程 EXECUTE运行存储过程 存储过程的创建者拥有存储过程的ALTER. ...

  10. python运维开发之第三天

    一.第二天课程的复习总结 1.列表可以增删改查,元组是不可修改的列表,字符串是不可以修改的. 2.列表,元组是有序的,字典是无序的,字典的key唯一 3.列表字典可以嵌套列表,可以嵌套字典,可以嵌套多 ...