1、用angular-cli建一个工程自带路由怎么做?

    命令:ng new  项目名 --routing

2、怎么使用路由器和路由器的一些基本使用。

//html页面

 <a routerLink="/page1r" routerLinkActive="active">page1</a>
<a routerLink="/page2" routerLinkActive="active">page2</a>
<a routerLink="/admin" routerLinkActive="active">Admin</a>
<a [routerLink]="[{ outlets: { popup: ['compose'] } }]">Contact</a> //'outlets'指定路由内容放置到那个router-outlet 容器内位置 <router-outlet></router-outlet>
<router-outlet name="popup"></router-outlet>
//ts页面
import { Routes, RouterModule } from '@angular/router'; 
const routes : Routes = [ {path: '',redirectTo:"/page1",pathMatch:"full"},//重定向
{path: 'page1',component:Page1Component},//路径定向
{path: 'page2',component:Page2Component},
{ path: 'compose', component: ComposeMessageComponent, outlet: 'popup' }, //路由到router-outlet属性名name 值为“popup”的路由容器上
{path: '**',component:Page404Component},//注意 路由是从上到下找的,所以不要把万能匹配放到前面去,不然在其后面的路由将会失效,
//所以404路由永远是放在最后面的
];
@NgModule(
{ imports: [ RouterModule.forRoot( appRoutes )//如果时分支路由这时要改成forChild(分支路由名) ],
exports: [ RouterModule ] }
)

3、路由传参

如果你想路由传参可用2种方式 :

  路由参数(paramMap)和查询参数(queryParamMap)中的参数访问;

如: 路由是这样写的

 

//路由位置 http://localhost:4200/page1/fan/page3/lia?fang=1&liang=2#qwer

<a  [routerLink]="['/page1','fan','page3','lia']" routerLinkActive="active" [queryParams]="{'fang':1,'liang':2}" fragment="qwer">page1</a>
{path: 'page1/:id/page3/:id1',component:Page1Component}

//  ..ts
import {ActivatedRoute} from '@angular/router';//路由参数获取用‘ActivatedRoute’
constructor(
private _activatedRoute:ActivatedRoute
) {
ngOnInit() {
this._activatedRoute.queryParamMap
.subscribe(rap=>{ //这时是获得查询参数{'fang':1,'liang':2}
      console.log(rap)
});
this._activatedRoute.paramMap
.subscribe(rap=>{//这里是获得路由参数{'id':1,'id1':2}
      console.log(rap)
})
}

总结:
  看了很多路angular路由文,反过来再看angular官网路由,发现其实官网写的最好,只是太多了,一时收获不了,当看多了细碎的路由文后再头看官网其实多读几篇就基本都知道用了

    官方:https://www.angular.cn/guide/router

angular 之路由的更多相关文章

  1. Angular 4 路由介绍

    Angular 4 路由 1. 创建工程 ng new router --routing 2. 创建home和product组件 ng g component home ng g component ...

  2. angular -- ng-ui-route路由及其传递参数?script标签版

    考虑到 多视图等因素,所以 angular 的路由考虑使用 ng-ui-route来做,而不使用 ng-route来做! <!DOCTYPE html> <html lang=&qu ...

  3. angular 前端路由不生效解决方案

    angular 前端路由不生效解决方案 Intro 最近使用 Angular 为我的活动室预约项目开发一个前后端分离的客户端,在部署上遇到了一个问题,前端路由不生效,这里记录一下.本地开发正常,但是部 ...

  4. Angular配置路由以及动态路由取值传值跳转

    Angular配置路由 1.找到 app-routing.module.ts 配置路由 引入组件 import { HomeComponent } from './home/home.componen ...

  5. angular的路由

    AngularJS 路由允许我们通过不同的 URL 访问不同的内容. 通过 AngularJS 可以实现多视图的单页Web应用(single page web application,SPA). 下面 ...

  6. angular中路由的实现(针对新手)

    最近搜了一下网上的教程,看完总感觉有点糊涂,对于新手来说可能云里雾里,所以写一个最简单的路由来给大家做个指引. 首先当然需要准备angular,下载地址:https://angular.io/ 现在a ...

  7. 关于Iscroll.js 的滑动和Angular.js路由冲突问题

    Iscroll主要应用于app移动端开发. 主要代码: window.onload=function(){ var myIscroll=new IScroll(".headerNav&quo ...

  8. 理解 angular 的路由功能

    相信很多人使用angular 都是因为他路由功能而用的 深入理解ANGULARUI路由_UI-ROUTER 最近在用 ionic写个webapp 看到几个demo中路由有好几种,搞的有点晕,查下资料研 ...

  9. Angular动画——路由动画及高阶动画函数

    一.路由动画 路由动画需要在host元数据中指定触发器.动画注意不要过多,否则适得其反. 内容优先,引导用户去注意到某个内容.动画只是辅助手段. 定义一个进场动画,一个离场动画. 因为进场动画和离场动 ...

随机推荐

  1. MySQL监控、性能分析——工具篇(转载)

    MySQL越来越被更多企业接受,随着企业发展,MySQL存储数据日益膨胀,MySQL的性能分析.监控预警.容量扩展议题越来越多.“工欲善其事,必先利其器”,那么我们如何在进行MySQL性能分析.监控预 ...

  2. 170605、防止sql注入(二)

    java filter防止sql注入攻击 原理,过滤所有请求中含有非法的字符,例如:, & <  select delete 等关键字,黑客可以利用这些字符进行注入攻击,原理是后台实现使 ...

  3. input输入框制定输入数据类型匹配

    <input type="text" id="price_169" value="97" style="max-width: ...

  4. 云笔记类APP推荐

    一.思绪收集类 Google Keep - 记事和清单 - Google Play 上的应用 注:谷歌 Keep 是最方便的收集思绪 APP 了.卡片视图,反应迅速,流畅,UI 漂亮,功能齐全,唯一不 ...

  5. Fundamental theorem of arithmetic 为什么1不是质数

    https://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic In number theory, the fundamental th ...

  6. Elasticsearch入门教程

    ElasticSearch是一个高度可扩展的开源搜索引擎并使用REST API,所以您值得拥有. 在本教程中,将介绍开始使用ElasticSearch的一些主要概念. 下载并运行ElasticSear ...

  7. 统计编程的框架与R语言统计分析基础——摘(2)统计分析之线性回归

    一.线性回归 1.简单线性回归 a. > x = women > x height weight 1 58 115 2 59 117 3 60 120 4 61 123 5 62 126 ...

  8. 史上最全的MonkeyRunner自动化测试从入门到精通(2)

    原文地址https://blog.csdn.net/liu_jing_hui/article/details/60955696 最基本脚本功能开始编写 (1)Monkeyrunner和Monkey的区 ...

  9. 为什么要同时重写equals和hashcode

    原文地址https://blog.csdn.net/tiantiandjava/article/details/46988461 原文地址https://blog.csdn.net/lijiecao0 ...

  10. 系统管理命令之id

    当我们想知道某个用户的UID和GID时id命令是非常有用的.一些程序可能需要UID/GID来运行.id使我们更加容易地找出用户的UID以GID而不必在/etc/group文件中搜寻. 1.获取指定用户 ...