[Angular 2] Router basic and Router Params
- 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的更多相关文章
- $router.query和$router.params的区别
类型于get(query) 和 post(params) 1.query方式传参和接收参数 传参: this.$router.push({ path:"/xxx" query: ...
- vue router使用query和params传参的使用
传参是前端经常需要用的一个操作,很多场景都会需要用到上个页面的参数,本文将会详细介绍vue router 是如何进行传参的,以及一些小细节问题.有需要的朋友可以做一下参考,希望可以帮到大家. Vue ...
- 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 ...
- vue 中router.go;router.push和router.replace的区别
vue 中router.go:router.push和router.replace的区别:https://blog.csdn.net/div_ma/article/details/79467165 t ...
- Angular入门(四) Router 替换当前页面
1.在 xx.html 中直接 写标签 <a [routerLink]="['/home']">home</a> 2.在 xx.html 中 ...
- [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 ...
- .6-浅析express源码之Router模块(2)-router.use
这一节继续深入Router模块,首先从最常用的use开始. router.use 方法源码如下: proto.use = function use(fn) { var offset = 0; var ...
- vue中router.go、router.push和router.replace的区别
router.go(n) 这个方法的参数是一个整数,意思是在history记录中向前或者后退多少,类似window.history.go(n) router.push(location) 想要导航到不 ...
- vue 中router.go、router.push和router.replace的区别
router.go(n) 这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n) router.push(location) 想要 ...
随机推荐
- 【USACO 3.3.1】骑马修栅栏
[描述] Farmer John每年有很多栅栏要修理.他总是骑着马穿过每一个栅栏并修复它破损的地方. John是一个与其他农民一样懒的人.他讨厌骑马,因此从来不两次经过一个栅栏.你必须编一个程序,读入 ...
- 对于HttpContext.Current的一点理解
string[] userInfomationSplits = HttpContext.Current.User.Identity.Name.Split(new string[] { "\\ ...
- .net截取指定长度汉字超出部分以指定的字符代替
下面是我在网上搜索,然后加以整理的关于在.net中截取指定长度汉字超出部分以指定的字符代替,来拓展一下自己的思路. 方法一 :在后台的select语句中直接操作或是在数据库中写一个存储过程 Selec ...
- select、pselect、poll和epoll的区别
select.pselect.poll和epoll函数是unix中具有I/O复用的函数.什么是I/O复用?为什么要有I/O复用?以及在什么场合下使用I/O复用?既然都具有I/O复用的功能,那这几个函数 ...
- rename 后缀
for file in $(find . -name "*.del" -type f);do mv "$file" "${file%.del}&quo ...
- CentOS 7 安装tomcat
1.下载Linux版的tomcat 2.上传下载tomcat文件到/usr/local中执行以下操作 [root@admin local]# cd /usr/local [root@admin loc ...
- codemirror 插件
做在线词典编辑的时候.里面有些自定义标签.类似html标签一样. 为了让编辑编辑.改成了 <动词></动词> 所以引用了 codemirror插件 此插件绝对牛逼 它主要功能 ...
- JAVA抽象类,接口,多态,抽象方法,一次列举
HEAD FIRST这系列的书,真的让人产生阅读的快感~~:) 和那套明日科技的一样,.. interface Nose { public int iMethod(); } abstract clas ...
- Hadoop MapReduce InputFormat/OutputFormat
InputFormat import java.io.IOException; import java.util.List; /** * InputFormat describes the input ...
- HDOJ 1285 确定比赛名次(拓扑排序)
Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...