angular路由模块(二)
上一章写的是如何创建一个简单的路由,这一样我们来看看如何创建一个路由模块。angular的思想就是(模块,组件,子组件.....)。
我们在src/app目录下创建一个跟路由模块app-routing.module.ts文件。
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angualr/router';//引入路由模块
import { CrisisListComponent } from './crisis-list.component';
import { HeroListComponent } from './hero-list.component';
//创建路由数组
const routes:Routes = [
{ path: 'crisis-center', component: CrisisListComponent },
{ path: 'heroes', component: HeroListComponent },
{ path: '', redirectTo: '/heroes', pathMatch: 'full' },
];
@ngModule({
imports:[RouterModule.forRoot(routes)],//路由配置
exports:[RouterModule] //一定要记得这个导出,不然会报错,
})
export class AppRoutingModule {
}
//把app.module.ts文件中的路由部分删除,添加app-routing.module.ts模块
import { AppRoutingModule } from './app-routing.module';
@NgModule({
imports:[AppRoutngModule]
})
这样就完成了,angular的路由模块化,但是这个模块还是在根路由,并没有说配置子路由,下节再说子路由实现。
angular路由模块(二)的更多相关文章
- angular服务二
angular服务 $http 实现客户端与服务器端异步请求 get方式 test.html <!DOCTYPE html> <html lang="en"> ...
- Angular基础(二) 组件的使用
一.简单操作 a) 使用Angular CLI可以快速创建项目框架,先运行 $ npm install –g @angular/cli@1.0.0安装CLI,为CLI的位置设置环境变量,然后就可以 ...
- 六、angular 生成二维码
首先需要安装angular-qrcode : bower install monospaced/angular-qrcode npm install angular-qrcode 如何使用? 在相应的 ...
- Angular(二)
Angular开发者指南(二)概念概述 template(模板):带有附加标记的模板HTMLdirectives(指令):使用自定义属性和元素扩展HTMLmodel(模型):用户在视图中显示的数据 ...
- angular学习(二):Controller定义总结
上文中总结完了ng-view的应用,将运维后台分开界面到2个,进行到 逻辑Controller处理中,本文将总结一下在项目中Controller都用到了哪些知识: $scope:作用域对象,仅仅是代表 ...
- Angular生成二维码
Installation - Angular 5+, Ionic NPM npm install angularx-qrcode --save Yarn yarn add angularx-qrcod ...
- 从flask视角理解angular(二)Blueprint VS Component
Component类似flask app下面的每个blueprint. import 'rxjs/add/operator/switchMap'; import { Component, OnInit ...
- Angular总结二:Angular 启动过程
要弄清楚 Angular 的启动过程,就要弄明白 Angular 启动时加载了哪个页面,加载了哪些脚本,这些脚本做了哪些事? 通过 Angular 的编译依赖文件 .angular-cli.json ...
- angular打包(二):nw.js
1 npm build 把ng编译出dist 2 单独写一个package.json 放在dist文件夹里. { "name": "app", "ma ...
随机推荐
- 案例分析——BAT业务https化经历
一.前言 通常的http访问会遭到中间人攻击.网络嗅探等普通用户感知不到的恶意行为,这些行为会篡改用户浏览页面引导用户访问非法网站.抓取用户的上网行为以及个人信息.严重的会造成用户 ...
- Docker第一弹:下载运行hello-world程序
1.需要安装好docker程序 没有安装的请看在centos 6.8下安装docker 2.从docker镜像仓库中拉去hello-world镜像 docker pull hello-world 3. ...
- yii2高级模板使用一个域名管理前后台
yii2的高级模板分为backend和frontend,最开始用yii的时候并没怎么在意,就使用了两个域名分别解析前后台.今天无意间看见 可以使用一个域名指向前后台. 1.修改 advanced/ba ...
- CentOS常用命令搜集
centos是32或者64位:getconf LONG_BIT
- session 与 coolie 的区别与联系
cookie 和session 的区别: session 在服务器端,cookie 在客户端(浏览器) cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗考虑到安全应当 ...
- vue项目中遇到的问题
在 export defaul new Router({ )} 这个路由配置中一定要加mode : 'history' 否者就会在路由前面默认添加# 路由跳转的几种方式: 在VUE中使用less来编译 ...
- MySQL之pymysql模块
MySQL之pymysql模块 import pymysql #s链接数据库 conn = pymysql.connect( host = '127.0.0.1', #被连接数据库的ip地址 po ...
- MyBatis入门一
本人只是刚刚学习MyBatis,作为学习路程的记录,写的不好,不完善的地方请多多包涵: 首先,先比较一下Hibernate和MyBatis两种框架之间的区别: 两种都是ORM框架,但是Hibernat ...
- AttributeError: 'TestLogin' object has no attribute 'driver' in Pycharm for python selenium
自动化测试学习中的问题: 最近几天在写登陆测试,遇到一个问题,困惑我的几个小时......... 我各种百度,花费大量时间,才找到我的问题的根本所在,最终解决了我的问题,主要是大小写的问题def Se ...
- VS2010 如何添加H文件目录和LIB目录
第一次使用VS2010,也是初学者开始编写VC++,程序首先学习编写DLL文件,编译完自己的DLL文件后,要在其它项目中使用,开始遇到很多错,但是在网上搜索了好久后,终于解决了问题. H文件目录: 依 ...