【问题标题】:Angular 8 routing, cant navigate to component without a name before slashAngular 8路由,在斜线之前无法导航到没有名称的组件
【发布时间】:2020-10-07 00:21:42
【问题描述】:

默认情况下,我希望浏览器在打开时导航到 LandingPageComponent

例如http://localhost:4200/

当用户在斜线后输入时,我想导航到 ProfileComponent 并在 URL 中使用参数

例如http://localhost:4200/user1

这种方法可行吗?由于我收到“路径不能以斜杠开头”的错误。

app-routing.module.ts

const routes: Routes = [

  {path:'', component:LandingPageComponent},
  {path: '/:profileId',
  loadChildren: './profile/profile.module#profileModule'
}, 
];
profile-routing.module.ts

const routes: Routes = [

{path:'', component:profileComponent},   //< I want to load this component after /user1
{path :'folder/:folderId', component:FolderComponent},
];

【问题讨论】:

    标签: angular routes navigation frontend


    【解决方案1】:

    app-routing.module.ts

    const routes: Routes = [
    
      {path:'', component:LandingPageComponent},
      {path: ':profileId',
      loadChildren: './profile/profile.module#profileModule'
    }, 
    ];
    

    从 profileId 的路径中删除“/”并尝试。

    【讨论】:

      猜你喜欢
      • 2019-07-27
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多