[Angular 2] Child Router
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的更多相关文章
- Angular.js之Router学习笔记
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- angular 的ui.router 定义不同的state 对应相同的url
Angular UI Router: Different states with same URL? The landing page of my app has two states: home-p ...
- http://angular.github.io/router/
Angular New Router Guide Configuring the Router- This guide shows the many ways to map URLs to compo ...
- [Angular] Auxiliary named router outlets
Define a auxilliary router: export const ROUTES: Routes = [ { path: 'folder/:name', component: MailF ...
- [Angular] Subscribing to router events
In our root component, one thing we can do is subscribe to Router events, and do something related t ...
- [Angular2 Router] Build Angular 2 Navigation with routerLink
Angular 2 navigation is configured using the routerLink directive. The routerLink directive behaves ...
- [转]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 ...
- AngularJS 使用 UI Router 实现表单向导
Today we will be using AngularJS and the great UI Router and the Angular ngAnimate module to create ...
- [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 ...
随机推荐
- 解决SQL Server的TEXT、IMAGE类型字段的长度限制
更多资讯.IT小技巧.疑难杂症等等可以关注 艾康享源 微信公众号. 来自为知笔记(Wiz)
- iOS开发之info.pist文件和.pch文件
iOS开发之info.pist文件和.pch文件 如果你是iOS开发初学者,不用过多的关注项目中各个文件的作用.因为iOS开发的学习路线起点不在这里,这些文件只会给你学习带来困扰. 打开一个项目,我们 ...
- javascript基础学习(十五)
javascript之cookie 学习要点: cookie介绍 创建与获取cookie cookie的编码 cookie的生存期 cookie的路径 cookie的domain cookie的sec ...
- HTML语义化标签(二)
为了保证网页去样式后的可读性,并且又符合web标准,应该注意一下几点: 1 尽可能少的使用无语义的标签div和span: 2 在语义不明显时,既可以使用div或者p时,尽量用p, 因为p在默认情况 ...
- JQuery学习笔记【CSS选择符】--02
Jquery的程序入口: <html> <head> <title></title> <script type="text/javasc ...
- [Python笔记]第九篇:re正则表达式
一.正则表达式基础 1.正则表达式介绍 正则表达式并不是Python的一部分.正则表达式是用于处理字符串的强大工具,拥有自己独特的语法以及一个独立的处理引擎,效率上可能不如str自带的方法,但功能十分 ...
- 简化的nginx多进程模型demo
//version 1:以下代码仅演示nginx多进程模型[test@vm c]$ cat mynginx.c#include <stdio.h> #include <string. ...
- 委托的lambda表达式
委托可以用 Lambda 表达式的方法来表示,很多C#的代码都会大量使用 Lambda 表达式,正确理解它的用法还是很重要的. 基础规则: Lambda 运算符 “=>” 左边表示委托实例所需要 ...
- HTTP 代理原理及实现
本文转载自 https://imququ.com/post/web-proxy.html HTTP 代理原理及实现(一) 文章目录 普通代理 隧道代理 Web 代理是一种存在于网络中间的实体,提供各式 ...
- 温故而知新 C++ 类型转换
C语言类型转换 在C语言里用到的类型转换方式,一般都是用强制类型转换,语法:(类型说明符)(表达式),例如: (float)a 把a转换为实型,(int)(x+y) 把x+y的结果转换为整型.C语言这 ...