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. ORACLE导入导出操作篇

    1. DIRECTORY 指定转储文件和日志文件所在的目录DIRECTORY=directory_objectDirectory_object用于指定目录对象名称.需要注意,目录对象是使用CREATE ...

  2. Hive学习之二 《Hive的安装之自定义mysql数据库》

    由于MySQL便于管理,在学习过程中,我选择MySQL. 一,配置元数据库. 1.安装MySQL,采用yum方式. ①yum  install  mysql-server,安装mysql服务端,安装服 ...

  3. php中const定义常量

    const 常量 1.在定义时必须被初始值,2.前面不加任何修饰符3.变量名字母一般都大写4.常量可以被子类继承5.一个常量是属于一个类的,而不是某个对象的 作用:当某些值是固定不变的,就用const ...

  4. 水仙花 AC 杭电

    水仙花数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  5. codevs 1017 乘积最大

    1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描 ...

  6. Android 子线程中进行UI操作遇到的小问题

    今天在学习<第一行Android代码>第9章-子线程进行UI操作时遇到了一些问题. 代码是这样的: ... import java.util.logging.Handler; ... pu ...

  7. 至芯FPGA培训中心-1天FPGA设计集训(赠送FPGA开发板)

    至芯FPGA培训中心-1天FPGA设计集训(赠送开发板) 开课时间2014年5月3日 课程介绍 FPGA设计初级培训班是针对于FPGA设计技术初学者的课程.课程不仅是对FPGA结构资源和设计流程的描述 ...

  8. html5 本地存储

    < ![CDATA[ 1. html本地存储操作 首先引用 <script src="Scripts/jquery-2.0.0.js"></script&g ...

  9. C51指针的使用

    指针就是指变量或数据所在的存储区地址.如一个字符型的变量 STR 存放在内存单元DATA 区的 51H 这个地址中,那么 DATA 区的 51H 地址就是变量 STR 的指针.在 C 语言中指针是一个 ...

  10. #define中 #与##的神奇用法linux学习 (转)

    #define中 #与##的神奇用法linux学习 (转) #define f(a,b) a##b #define d(a) #a #define s(a) d(a) void main( void ...