[英]add sub Route in the beginning of route path (angular)
I have angular project and I need when user type the URL like www.mysite.com/hisName , Take this name and add it to all routing pages in my project and the final result will be like www.mysite.com/hisName/home我有 angular 项目,当用户键入 URL 时,我需要像www.mysite.com/hisName一样,取这个名字并将它添加到我项目中的所有路由页面,最终结果将像www.mysite.com/hisName/home
this is my routing code这是我的路由代码
import { NgModule } from "@angular/core";
import { Routes, RouterModule } from "@angular/router";
import { AppComponent } from "./app.component";
const routes: Routes = [
{ path: "", redirectTo: "home", pathMatch: "full" },
{ path: "home", component: HomeComponent },
path: "supliers",
loadChildren: () =>
import("./supliers-container/supliers-container.module").then(
(mod) => mod.SupliersContainerModule
),
}
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule],
})
export class AppRoutingModule {}
I think you are asking for something like a wildcard option?我想你是在要求通配符之类的东西? It does have to be defined as the last element.它确实必须定义为最后一个元素。
const routes: Routes = [
{ path: "", redirectTo: "home", pathMatch: "full" },
{ path: "home", component: HomeComponent },
{ path: "supliers",
loadChildren: () =>
import("./supliers-container/supliers-container.module").then(
(mod) => mod.SupliersContainerModule
),
},
{ path "**", redirectTo: "home", pathMatch: "full" } // here
]
Note: if you add the wildcard, I don't think you need the first path option.注意:如果您添加通配符,我认为您不需要第一个路径选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.