Angular4 - 带参数的嵌套路由 [英] Angular4 - Nested route with params

查看:38
本文介绍了Angular4 - 带参数的嵌套路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Angular4 中获得了我的用户配置文件的路由

I got a routing for my user profiles in Angular4

/* Frame Default */
{
    path: '', component: FrameDefaultComponent,
    children: [
        {path: 'home', component: SiteHomeComponent},
        {path: 'home/:page', component: SiteHomeComponent},
        {
            path: 'user/:id', component: SiteUserProfileComponent,
            children: [
                {path: '', redirectTo: 'home', pathMatch: 'full'},
                {path: 'home', component: SiteUserProfileHomeComponent},
                {path: 'about', component: SiteUserProfileAboutComponent}
            ]
        },
        {
            path: 'user/settings', component: SiteUserSettingsComponent,
            children: [
                {path: '', redirectTo: 'home', pathMatch: 'full'},
                {path: 'home', component: SiteUserProfileHomeComponent},
                {path: 'about', component: SiteUserProfileAboutComponent}
            ]
        },
        {path: 'demo', component: SiteDemoComponent}
    ]
},

问题是,当我导航到用户/设置时,他尝试打开用户/:id ...知道如何解决这个问题吗?

The problem is that when i navigate to user/settings he try to open user/:id ... any idea how i can fix this problem?

推荐答案

尝试像这样改变你的路由顺序

Try to change the order of your routes like this

{
  path: '', component: FrameDefaultComponent,
  children: [
  {path: 'home', component: SiteHomeComponent},
  {path: 'home/:page', component: SiteHomeComponent},
  {
    path: 'user/settings', component: SiteUserSettingsComponent,
    children: [
      {path: '', redirectTo: 'home', pathMatch: 'full'},
      {path: 'home', component: SiteUserProfileHomeComponent},
      {path: 'about', component: SiteUserProfileAboutComponent}
    ]
  },
  {
    path: 'user/:id', component: SiteUserProfileComponent,
    children: [
      {path: '', redirectTo: 'home', pathMatch: 'full'},
      {path: 'home', component: SiteUserProfileHomeComponent},
      {path: 'about', component: SiteUserProfileAboutComponent}
    ]
  },
  {path: 'demo', component: SiteDemoComponent}
]
},

这篇关于Angular4 - 带参数的嵌套路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆