• When we define router in Angualr 2, we use @RouteConcfig()
  • When we want to display component, we use <router-outlet>
  • When we want to navigate to component, we use [routerLink]="['routerName']"
  • When we want to access router params, we use RouterParams
  • When we want to access Rotuer itself, we use Router

1. In index.html:

<base href="/">

2. Include router file:

import 'angular2/router';

3. Inject the provider:

bootstrap(App, [
ROUTER_PROVIDERS
]);

4. @RouterConfig:

@RouteConfig([
{path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true},
{path: '/about', name: 'About', component: AboutComponent}
])

5. Inject ROUTER_DIRECTIVES:

directives: [HomeComponent, AboutComponent, ROUTER_DIRECTIVES],

6. Define the link:

        <a href="" [routerLink]="['Home']">Home</a>
<a href="" [routerLink]="['Home', {username: 'Hero'}]">Owner</a>
<a href="" [routerLink]="['About']">About</a>

7. Define the router-outlet:

        <nav>
<a href="" [routerLink]="['Home']">Home</a>
<a href="" [routerLink]="['Home', {username: 'Zhentian Wan'}]">Owner</a>
<a href="" [routerLink]="['About']">About</a>
</nav>
<router-outlet></router-outlet>

8. If deal with RouterParams:

    constructor(private _routeParams: RouteParams){
this.username = _routeParams.get('username');
}

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

[Angular 2] Router basic and Router Params的更多相关文章

  1. $router.query和$router.params的区别

    类型于get(query) 和 post(params) 1.query方式传参和接收参数   传参: this.$router.push({ path:"/xxx" query: ...

  2. vue router使用query和params传参的使用

    传参是前端经常需要用的一个操作,很多场景都会需要用到上个页面的参数,本文将会详细介绍vue router 是如何进行传参的,以及一些小细节问题.有需要的朋友可以做一下参考,希望可以帮到大家. Vue ...

  3. vue router.push(),router.replace(),router.go()和router.replace后需要返回两次的问题

    转载:https://www.cnblogs.com/lwwen/p/7245083.html https://blog.csdn.net/qq_15385627/article/details/83 ...

  4. vue 中router.go;router.push和router.replace的区别

    vue 中router.go:router.push和router.replace的区别:https://blog.csdn.net/div_ma/article/details/79467165 t ...

  5. Angular入门(四) Router 替换当前页面

    1.在 xx.html 中直接 写标签       <a [routerLink]="['/home']">home</a>   2.在 xx.html 中 ...

  6. [Angular2 Router] Lazy Load Angular 2 Modules with the Router

    Angular 2 lazy loading is a core feature of Angular 2. Lazy loading allows your application to start ...

  7. .6-浅析express源码之Router模块(2)-router.use

    这一节继续深入Router模块,首先从最常用的use开始. router.use 方法源码如下: proto.use = function use(fn) { var offset = 0; var ...

  8. vue中router.go、router.push和router.replace的区别

    router.go(n) 这个方法的参数是一个整数,意思是在history记录中向前或者后退多少,类似window.history.go(n) router.push(location) 想要导航到不 ...

  9. vue 中router.go、router.push和router.replace的区别

    router.go(n) 这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n) router.push(location) 想要 ...

随机推荐

  1. java_annotation_01

    一,Annotation简介 J2SE5.0提供了很多新的我,其中一个很重要的我就是对元数据的支持,在J2SE5.0中,这种元数据被称为注释,通过使用注释,程序开发人员可以在不改变原有逻辑的情况下,在 ...

  2. Qt中绘图坐标QPainter,Viewport与Window的关系

    在Qt中常常要自己重载一些paintEvent函数,这个时候往往忽略了两个很关键的API,那就是setViewport和setWindow. Viewport,顾名思义,反应的是物理坐标,就是你实际想 ...

  3. JQUERY1.9学习笔记 之内容过滤器(四) parent选择器

    描述:选择至少包含一个子节点的元素(一个标签或是文本). 例:找出所有有子元素的td标签,包含文本. <!doctype html><html lang="en" ...

  4. php 带cookie采集某页面

    <?php error_reporting(0); define("temp_dir", dirname(__FILE__)."/Public/"); d ...

  5. jquery 节点操作大全

    $para.attr("title"); 实例: <script type="text/javascript"> //<![CDATA[ $( ...

  6. python抓取网页图片

    本人比较喜欢海贼王漫画,所以特意选择了网站http://www.mmonly.cc/ktmh/hzw/list_34_2.html来抓取海贼王的图片. 因为是刚刚学习python,代码写的不好,不要喷 ...

  7. Python新手学习基础之数据结构-列表1

    创建一个列表 讲完了序列,我们现在来讲讲Python中最常见的一种序列数据类型--列表. 列表创建的语法是: list_name = [item1, item2, item3, .......] 列表 ...

  8. js中typeof的用法

    一. 经常会在js里用到数组,比如 多个名字相同的input, 若是动态生成的, 提交时就需要判断其是否是数组. if(document.mylist.length != "undefine ...

  9. MySQL的索引

    MySQL索引 索引:是一种特殊的文件(InnoDB 数据表上的索引是表空间的一个组成部分),它们包含着对数据表里所有记录的引用指针.其可以加快数据读操作,但会使数据写操作变慢:应该构建在被用作查询条 ...

  10. IOS学习:常用第三方库(GDataXMLNode:xml解析库)

    IOS学习:常用第三方库(GDataXMLNode:xml解析库) 解析 XML 通常有两种方式,DOM 和 SAX: DOM解析XML时,读入整个XML文档并构建一个驻留内存的树结构(节点树),通过 ...