如何在Angular 4中设置默认用户idName?
我怎样才能有一个默认的路由,比如如何在Angular 4中设置默认用户idName?,angular,default,angular-routerlink,Angular,Default,Angular Routerlink,我怎样才能有一个默认的路由,比如home/Welcome,目前我的路由只是作为,我希望用户有默认的idName作为Welcome 我的路线设置为: const marketRoutes:Routes = [ {path:'',redirectTo:'home',pathMatch: 'full'}, {path:'home',component:HomecontainerComponent,children:[ {path:':idName',component
home/Welcome
,目前我的路由只是作为,我希望用户有默认的idName作为Welcome
我的路线设置为:
const marketRoutes:Routes = [
{path:'',redirectTo:'home',pathMatch: 'full'},
{path:'home',component:HomecontainerComponent,children:[
{path:':idName',component:ContentdetailsComponent} // would like to have
default idNameset up as Welcome so that details page would have initial
value Welcome
]},
{ path: '**', redirectTo: 'home' }
];
我的ContentDetails组件html如下所示:
市场门户
Lorem Ipsum只是印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是行业标准的虚拟文本。
洞察力
使能获胜
帐户最佳做法
帐户最佳做法
帐户最佳做法
帐户最佳做法
您可以尝试此解决方案
我已经创建了演示
你可以试试这个解决方案 我已经创建了演示 请尝试以下代码: 在
子对象数组中添加另一个路由路径
{path:'',重定向到:'welcome',pathMatch:'full'}
将其重定向到home/welcome
const marketRoutes:Routes = [
{path:'',redirectTo:'home',pathMatch: 'full'},
{path:'home', component:HomecontainerComponent,children:[
{path:'', redirectTo:'welcome', pathMatch: 'full'} // Redirects to home/welcome
{path:':idName',component:ContentdetailsComponent}
]},
{ path: '**', redirectTo: 'home' }
];
请尝试以下代码:
在子对象数组中添加另一个路由路径
{path:'',重定向到:'welcome',pathMatch:'full'}
将其重定向到home/welcome
const marketRoutes:Routes = [
{path:'',redirectTo:'home',pathMatch: 'full'},
{path:'home', component:HomecontainerComponent,children:[
{path:'', redirectTo:'welcome', pathMatch: 'full'} // Redirects to home/welcome
{path:':idName',component:ContentdetailsComponent}
]},
{ path: '**', redirectTo: 'home' }
];