Angular路由不起作用(错误:无法找到网站)。
创始人
2024-10-28 01:00:13
0
  1. 确认路由模块是否正确导入到应用中,例如:

import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { HomeComponent } from './home/home.component'; import { AboutComponent } from './about/about.component';

const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'about', component: AboutComponent } ];

@NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule { }

  1. 确认应用是否设置了基本URL,例如:

import { Component } from '@angular/core'; import { Router } from '@angular/router';

@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { constructor(private router: Router) { this.router.navigate(['/']); } }

  1. 如果项目位于子目录中,请使用相对URL,例如:

Product

  1. 如果URL中包含特殊字符,请使用encodeURIComponent()编码,例如:

let id = '123#456' this.router.navigate(['/product', encodeURIComponent(id)]);

通过以上操作可以解决Angular路由不起作用的错误。

相关内容

热门资讯

透视教程!德普之星辅助软件(透... 透视教程!德普之星辅助软件(透视)免费透视(切实真的有挂);1、每一步都需要思考,不同水平的挑战会更...
透视存在!aapoker插件(... 透视存在!aapoker插件(透视)真的假的(好像真的是有挂)1、很好的工具软件,可以解锁游戏的aa...
透视了解!德普辅助器辅助器怎么... 透视了解!德普辅助器辅助器怎么用(透视)辅助器(切实存在有挂);1、德普辅助器辅助器怎么用ai辅助优...
透视透视!aapoker如何设... 透视透视!aapoker如何设置胜率(透视)透视软件(确实真的有挂);1、实时aapoker如何设置...
透视苹果版!德普之星透视辅助软... 透视苹果版!德普之星透视辅助软件激活码(透视)透视软件免费入口官网(一贯存在有挂)德普之星透视辅助软...
透视最新!aapoker发牌逻... 透视最新!aapoker发牌逻辑(透视)万能辅助器(都是存在有挂)1、下载好aapoker发牌逻辑辅...
透视ai代打!德普之星辅助软件... 透视ai代打!德普之星辅助软件(透视)辅助器app(其实是真的有挂)1、点击下载安装,德普之星辅助软...
透视好友房!aapoker安装... 透视好友房!aapoker安装包怎么使用(透视)透视脚本(都是真的是有挂);1、aapoker安装包...
透视透视挂!德扑圈透视挂(透视... 透视透视挂!德扑圈透视挂(透视)透视辅助(一贯是真的有挂)1、德扑圈透视挂系统规律教程、德扑圈透视挂...
透视好友!德普之星app安卓版... 透视好友!德普之星app安卓版破解版(透视)app安卓版破解版(一直有挂)所有人都在同一条线上,像星...