Angular学习记录8:路由

本文是Angular学习笔记,主要介绍了Angular路由的基础配置,包括配置Routes、RouterOutlet和RouterLink。探讨了HTML5 routing strategy(PathLocationStrategy)和HashLocationStrategy的区别,并展示了如何创建路由参数和嵌套路由。同时,提到了登陆验证的实现,通过auth.service.ts和logged-in.guard.ts进行简单阐述,但未深入结合后端验证。

之前用过dva、umi等前端框架/库,对路由有一定的了解,所以学起来还好。

1 基础

页面就是路由。

There are three main components that we use to configure routing in Angular:

  • Routes describes the routes our application supports
  • RouterOutlet is a “placeholder” component that shows Angular where to put the content of each route
  • RouterLink directive is used to link to routes

首先搞了about、contact、home三个component

然后在app.module.ts中定义好路由:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AboutComponent } from './about/about.component';
import { ContactComponent } from './contact/contact.component';
import { HomeComponent } from './home/home.component';

// routing goes here
import {
  RouterModule,
  Routes
} from '@angular/router';

const routes: Routes = [
  // basic routes
  {path: '', redirectTo: 'home', pathMatch: 'full'},
  {path: 'home', component: HomeComponent},
  {path: 'about', component: AboutComponent},
  {path: 'contact', component: ContactComponent},
  {path: 'contactus', redirectTo: 'contact'},
];

@NgModule({
  d
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值