使用Angular Router导航基础
名称 |
简介 |
|
Routes |
路由配置,保存着那个URL对应着哪个组件,以及在哪个RouterOulet中展示组件。 |
|
RouterOutlet |
在HTML中标记路由内容呈现位置的占位符指令。 |
|
Router |
负责在运行时执行路由的对象,可以通过调用其navigate()和navigateByUrl()方法来导航到一个指定路由。 |
|
routerLink |
在HTML中申明路由导航用的指令。 |
|
ActivatedRoute |
当前激活的路由对象,保存着当前路由的信息,如路由地址,路由参数等。 |
实例:
1.创建一个Angular Router项目;(ng new Router -routing)
2.新建两个组件home和product;
ng g component home
ng g component product
完成后项目结构截图

3.配置app.routing.module.ts文件如下
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {HomeeComponent} from "./homee/homee.component";
import {ProductComponent} from "./product/product.component";
const routes: Routes = [
{path: '', component: HomeeComponent},
{path: 'product', component: ProductComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
4.修改app.component.html文件如下
<!--The content below is only a placeholder and can be replaced.-->
<a [routerLink]="['/']">主页</a>
<a [routerLink]="['/product']">商品详情</a> <router-outlet></router-outlet>
保存,运行,angular router导航基础完成


使用Angular Router导航基础的更多相关文章
- [从 0 开始的 Angular 生活]No.38 实现一个 Angular Router 切换组件页面(一)
前言 今天是进入公司的第三天,为了能尽快投入项目与成为团队可用的战力,我正在努力啃官方文档学习 Angular 的知识,所以这一篇文章主要是记录我如何阅读官方文档后,实现这个非常基本的.带导航的网页应 ...
- Angular路由——路由基础
一.路由相关对象 Router和RouterLink作用一样,都是导航.Router是在Controller中用的,RouterLink是在模版中用到. 二.路由对象的位置 1.Routes对象 配置 ...
- Angular+Bootstrap3导航菜单
Angular+Bootstrap3导航菜单 AngularJS体验式编程系列文章,将介绍如何用angularjs构建一个强大的web前端系统.angularjs是由Google团队开发的一款非常优秀 ...
- Angular Route导航
我们用Angular cli创建带有路由的新项目 ng new router --routing Angular Routes API文档 Angular的文档中有详细的解释: 1)https://a ...
- angular学习-入门基础
angular .caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #00 ...
- MVC route 和 Angular router 单页面的一些方式
直接看代码和注释吧 ASP.NET MVC router public class RouteConfig { public static void RegisterRoutes(RouteColle ...
- angular 实现导航ng-click切换
angular写的导航.自学angular已有一段时间. <!doctype html><html lang="en"><head> <m ...
- Angular学习笔记—基础(转载)
创建简单组件 新建组件 $ ng generate component simple-form --inline-template --inline-style # Or $ ng g c simpl ...
- [Angular Router] Lazy loading Module with Auxiliary router
Found the way to handle Auxiliary router for lazy loading moudle and erge load module are different. ...
随机推荐
- JAVA NIO 主要概念
NIO有三个主要概念: buffer channel selector channel间通过buffer通信,channel在selector注册后,可以由selector管理,实现非阻塞编程 buf ...
- bootstrap 鼠标悬停显示
1. <button type="button" rel="drevil" data-content="报名截止时间:'+time+'" ...
- spacemacs及python学习-坑之记录
Table of Contents 1. spacemacs 1.1. .spacemacs 文件 1.2. 项目文件 1.3. open shell windows 1.4. emacs基础 1.4 ...
- Django+Nginx+uWSGI部署
一.介绍 Django的部署可以有多种方式,采用nginx+uwsgi的方式是最常见的一种方式.在这种方式中,将nginx作为服务器前端,接收WEB的所有请求,统一管理请求.nginx把所有静态请求自 ...
- Supervised Learning and Unsupervised Learning
Supervised Learning In supervised learning, we are given a data set and already know what our correc ...
- .8-Vue源码之AST(4)
上一节讲完了超长的start函数,也同时完结了handleStartTag函数,接着continue进入下一轮while循环. 此时剩余的字符串状态如图:,切掉了<div id='app'> ...
- 推荐一款不错的反编译软件:Reflector
只需要把要反编译的dll拖放到程序窗口就可以看到code了.是不是很简单,快来试试吧.不只是可以反编译个人写的code,.Net库一样可以查看代码.想学习.Net核心代码的可以试试看.
- showmemory.c 和 hello.s 源码
showmemory.c 和 hello.s 源码 /** * showmemory.c -- print the position of different types of data in a p ...
- Problem E
Problem Description 省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).现得到城镇道路统计 ...
- django 实现同一个ip十分钟内只能注册一次(redis版本)
上一篇文章,django 实现同一个ip十分钟内只能注册一次 的时候,我们在注册的时候选择使用的使我们的数据库来报错我们的注册的ip信息,可是如果数据量大,用户多的时候,单单靠我们的数据库 来储存我们 ...