带参数的角度路由,带参数的重定向路由与不带参数的路由分开

时间:2019-04-04 07:16:52

标签: angular angular-router

在Angular(v7)应用程序中,我具有如下的路由设置:

dcast(mm, Var1 ~ Var2, value.var="value")[-1]
#   1 2 3 4
# 1 0 1 2 3
# 2 1 0 4 5
# 3 2 4 0 6
# 4 3 5 6 0

我希望发生的是这样的URL:

m <- structure(c(0, -1, -2, -3, 1, 0, -4, -5, 2, 4, 0, -6, 3, 5, 6, 0), .Dim = c(4L, 4L))
mm <- data.table::melt(m)

路由器将重定向到Image组件,并重定向到这样的URL:

export const routes: Routes = [
  {
    path: '', 
    component: HomeComponent,
    children: [{
      path: '',
      component: Main
    },
    {
      path: 'main',
      component: Main
    },
     {
      path: 'search/:imageid',
      component: Image
    }, 
    {
      path: 'search',
      component: Search
    }]
}]

路由器将重定向到“搜索”组件,但“搜索”同时获取了两者,并且绕过了通往“图片”的路由。

我不确定我在这里想念什么。

1 个答案:

答案 0 :(得分:1)

您不需要重复路径变量的名称。

您应使用的路径为domain.com/#/search/512,路由器将按预期处理该变量。

(请确保您正确定义了HashLocationStrategy)。

此外,了解路由上pathMatch: 'full'属性的存在可能会很有用,该属性允许匹配整个路径而不仅仅是前缀。这可能是这里的问题,但这不是因为您放置子级路线的顺序。看一下this place in the official docs以获得更精确的开发。

相关问题