[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) 想要 ...
随机推荐
- c# 学习笔记(三)
程序集程序集的私有部署 不用在注册表中注册组件卸载只需要从文件系统中删除他即可 共享程序集和GAC 只有强命名程序集能被添加到GAC中程序集数据签名只需在安装到GAC时检查一次 GAC内的并肩执行GA ...
- 七、C# 接口
并非只能通过继承使用多态性,还能通过接口使用它. 和抽象类不同,接口不包含任何实现(方法). 然后和抽象类相似,接口也定义了一系列成员,调用者可以依赖这些成员来支持一个特定的功能. 实现接口的类会 ...
- 【C#学习笔记】一、基础知识
1.1数据类型(P43) 类型 别名 允许的值 sbyte System.SByte -128~127 byte System.Byte 0~255 short System.Int16 -32768 ...
- JavaScript--机选双色球
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- plist解析, 简易实现.
源码 class Xml { public: typedef std::pair<std::wstring, std::wstring> NodeT; static std::vector ...
- Qt中widget重新setParent需要注意的问题
有时候需要在widget中重新setParent,但会发现setParent有时候会出现问题,比如子窗口不在刷出来等等. 其实,有一点是需要注意的,就是Qt文档里说的,如果你当前widget重新设置了 ...
- jquery mobile 栅格化
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- centos7 服务器安装nginx,mysql,php
一.概述 项目的需要,今天在虚拟机上基于Centos安装配置了服务器运行环境,web服务用 nginx,数据库存储在mysql,动态脚本语言是php. 二.步骤 首页保证Centos7已经安装完毕,正 ...
- Thinkphp 文本编辑器
文本编辑器:可以从网上下载---ueditor文件夹里面包含php和utf8-php两个文件夹 平时使用时主要用到获取内容和写入内容两个按钮 获取内容: <!DOCTYPE html PUBLI ...
- 纯js实现分页
原理:所有数据已加载好,js通过遍历部分显示,实现分页效果 html代码 <html> <head> <meta charset='utf-8'> <scri ...