问题描述
我正在开发一个 Angular 项目,我想从 URL 中隐藏路径。我不使用导航。这就是我需要的是,当我进入网站时只看到 www.hgshgs.gr 而不是 www.hgshgs.gr/pages/dashboard。有没有办法做到这一点?
page-routing.module.ts
const routes: Routes = [{
path: '',component: PagesComponent,children: [
{
path: 'dashboard',component: ECommerceComponent,},{
path: 'iot-dashboard',component: DashboardComponent,{
path: '',redirectTo: 'iot-dashboard',pathMatch: 'full',{
path: '**',component: NotFoundComponent,],}];
@NgModule({
imports: [RouterModule.forChild(routes)],exports: [RouterModule],})
解决方法
你可以在声明 Router.forRoot 时使用如下
imports: [ RouterModule.forRoot(routes,{ initialNavigation : false }) ]