diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index e76731c..bd2a25b 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -4,7 +4,7 @@ * @Author: Ruin 🍭 * @Date: 2022-03-03 16:21:23 * @LastEditors: 刘引 - * @LastEditTime: 2022-03-09 10:52:56 + * @LastEditTime: 2022-03-09 14:00:45 */ import { NgModule } from "@angular/core"; import { RouterModule, Routes } from "@angular/router"; @@ -20,6 +20,11 @@ const routes: Routes = [ path: "user", component: UserComponent, }, + // 匹配不到路由时加载的组件或者跳转的路由 + { + path: "**", + redirectTo: "", + }, ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0e2494f..e39639a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -4,7 +4,7 @@ * @Author: Ruin 🍭 * @Date: 2022-03-03 16:21:23 * @LastEditors: 刘引 - * @LastEditTime: 2022-03-09 11:39:39 + * @LastEditTime: 2022-03-09 13:41:44 */ // 引入核心模块 import { NgModule } from "@angular/core"; diff --git a/src/app/model/public.module.ts b/src/app/model/public.module.ts index 65b666d..550ebdc 100644 --- a/src/app/model/public.module.ts +++ b/src/app/model/public.module.ts @@ -4,7 +4,7 @@ * @Author: Ruin 🍭 * @Date: 2022-03-09 11:13:29 * @LastEditors: 刘引 - * @LastEditTime: 2022-03-09 11:40:26 + * @LastEditTime: 2022-03-09 13:39:27 */ import { NgModule } from "@angular/core"; import { AppRoutingModule } from "../app-routing.module"; @@ -12,9 +12,10 @@ import { ComponentsModule } from "src/app/components/components.module"; import { CommonModule } from "@angular/common"; // 引入双向数据绑定 import { FormsModule } from "@angular/forms"; + @NgModule({ declarations: [], - imports: [AppRoutingModule, ComponentsModule, FormsModule, CommonModule], + imports: [], exports: [AppRoutingModule, ComponentsModule, FormsModule, CommonModule], }) export class PublicModule {} diff --git a/src/app/pages/home/home.component.html b/src/app/pages/home/home.component.html index 9ca3524..4ccdf84 100644 --- a/src/app/pages/home/home.component.html +++ b/src/app/pages/home/home.component.html @@ -4,7 +4,7 @@ * @Author: Ruin 🍭 * @Date: 2022-03-03 17:06:15 * @LastEditors: 刘引 - * @LastEditTime: 2022-03-09 10:55:03 + * @LastEditTime: 2022-03-09 14:01:40 -->
@@ -15,10 +15,14 @@
- 跳转 + 跳转回主页 + + 跳转
- + diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index 6c779be..7c88865 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -4,12 +4,13 @@ * @Author: Ruin 🍭 * @Date: 2022-03-03 17:06:15 * @LastEditors: 刘引 - * @LastEditTime: 2022-03-08 14:38:05 + * @LastEditTime: 2022-03-09 13:47:01 */ import { Component, ElementRef, OnInit, ViewChild } from "@angular/core"; import { RequestService } from "src/app/services/request.service"; // 引入服务 import { StorageService } from "src/app/services/storage.service"; +import { ActivatedRoute } from "@angular/router"; @Component({ selector: "app-home", templateUrl: "./home.component.html", @@ -18,7 +19,12 @@ import { StorageService } from "src/app/services/storage.service"; export class HomeComponent implements OnInit { @ViewChild("homeHead", { static: true }) homeHead: any; public result: any = ""; - constructor(public storage: StorageService, public request: RequestService) {} + public key: string = "123"; + constructor( + public storage: StorageService, + public request: RequestService, + public route: ActivatedRoute + ) {} // init结尾的函数只会调用一次 checked结尾的函数会多次调用 // 初始化组件和指令时调用(一般用于请求api) ngOnInit(): void { diff --git a/src/app/pages/home/home.module.ts b/src/app/pages/home/home.module.ts index 6f713d5..06a9eed 100644 --- a/src/app/pages/home/home.module.ts +++ b/src/app/pages/home/home.module.ts @@ -4,13 +4,14 @@ * @Author: Ruin 🍭 * @Date: 2022-03-03 17:06:01 * @LastEditors: 刘引 - * @LastEditTime: 2022-03-09 11:54:23 + * @LastEditTime: 2022-03-09 13:39:03 */ import { NgModule } from "@angular/core"; import { HomeComponent } from "./home.component"; import { HeadComponent } from "./components/head/head.component"; import { BodyComponent } from "./components/body/body.component"; import { PublicModule } from "src/app/model/public.module"; + @NgModule({ declarations: [HomeComponent, HeadComponent, BodyComponent], imports: [PublicModule], diff --git a/src/app/pages/user/user.component.html b/src/app/pages/user/user.component.html index 3e01196..32af0b2 100644 --- a/src/app/pages/user/user.component.html +++ b/src/app/pages/user/user.component.html @@ -4,13 +4,15 @@ * @Author: Ruin 🍭 * @Date: 2022-03-04 10:45:56 * @LastEditors: 刘引 - * @LastEditTime: 2022-03-09 10:56:33 + * @LastEditTime: 2022-03-09 13:23:58 -->

user works!

- 跳转回主页 + 跳转回主页 + + 跳转