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. Android开源项目 Universal imageloader 源码研究之项目框架

    Universal imageloader 的代码并不复杂 重点是缓存,线程池任务 下面都用UML图进行了绘制 基本使用流程就是 初始化配置,设置Options参数,最后Dispaly提交下载 pub ...

  2. myeclipse 'no default proposals' when use 'alt + /'.

    solution: Window -> Preferences -> Java -> Editor -> Content Assist -> Advanced in th ...

  3. dotnet与各种数据库类型对应关系

    Data Provider Parameter format sqlclient @parametername oledb ?    mark odbc ?   mark oracleclient : ...

  4. 【转】Auto Layout 进阶

    原文:http://blog.csdn.net/ysy441088327/article/details/12558097   引言: Auto Layout是iOS6发布后引入的一个全新的布局特性, ...

  5. MySQL被Oracle并购后的409个日日夜夜

    2009年4月20日,Oracle并购了Sun,这也意味着MySQL归属到甲骨文的旗下.四百多天过去了,究竟这场并购结局如何?请看本文. 去年对Sun的收购,让甲骨文顺利的将一个潜在的对手MySQL收 ...

  6. c#结构体和字节数组的转换、字节数组和stream的转换

    本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/streambytsstruct.html using System; using ...

  7. 你好,C++(4)2.1.3 我的父亲母亲:编译器和链接器 2.1.4 C++程序执行背后的故事

    2.1.3  我的父亲母亲:编译器和链接器 从表面上看,我是由Visual Studio创建的,而实际上,真正负责编译源代码创建生成可执行程序HelloWorld.exe的却是Visual Studi ...

  8. 利用C++ RAII技术自动回收堆内存

    在C++的编程过程中,我们经常需要申请一块动态内存,然后当用完以后将其释放.通常而言,我们的代码是这样的: 1: void func() 2: { 3: //allocate a dynamic me ...

  9. JavaScript作用域链详解

    JavaScript的作用域链还是很有味道的,搞懂了这个知识点,闭包的问题也就迎刃而解咯 1.JavaScript的全局变量和局部变量 首先,先来看看js的全局变量和局部变量,js不是块级作用域,所以 ...

  10. extjs combobox 设置下拉时显示滚动条 设置显示条数

    extjs在点击下拉时如果没有限制它的高度,那么它的默认最大高度是300,显示的时候就会显示300的高度,知道选项内容超过这个高度时才会自动显示滚动条,往往在有些时候我们希望让combobox显示一个 ...