Aurelia路线匹配

时间:2017-07-20 17:34:34

标签: routing aurelia aurelia-router

注意:启用了pushState

我有一个与aurelia路线匹配相关的问题/问题。我在 app.ts

中有以下路线
{
  route: ['profile'],
  href: '#',
  name: 'profile',
  moduleId: PLATFORM.moduleName('../pages/profile', 'profile'),
  title: 'Profile'
},
{
  route: [':continents/:countries'],
  name: 'countries',
  moduleId: PLATFORM.moduleName('../pages/countries', 'countries'),
  title: 'Countries'
}

profile.ts 模块中,我执行另一个configRoute,其中我设置了另外两个子路由,例如:

{
  route: ['personal'],
  href: '#',
  name: 'personal',
  moduleId: PLATFORM.moduleName('./personal', 'personal'),
  title: 'Personal'
},
{
  route: ['skills'],
  href: '#',
  name: 'skills',
  moduleId: PLATFORM.moduleName('./skills', 'skills'),
  title: 'Skills'
}

问题如下:当我导航到/profile/skills/profile/personal时,路线将与国家/地区(':continents/:countries')匹配。我认为这是有道理的,因为整个部分与之匹配。

我可以将个人资料路线更改为

{
  route: ['profile', 'profile/:tabName'],
  href: '#',
  name: 'profile',
  moduleId: PLATFORM.moduleName('../pages/profile', 'profile'),
  title: 'Profile'
},

但我的路线就像/profile/personal/personal/profile/personal/skills,我不想要。

我尝试按照aurelia docs中的建议添加通配符:

{
  route: ['profile', 'profile/*tabName'],
  href: '#',
  name: 'profile',
  moduleId: PLATFORM.moduleName('../pages/profile', 'profile'),
  title: 'Profile'
},

但是像/profile/skills这样的路线与之匹配,它仍然会转到':continents/:countries'

我可以以某种方式强迫它转到profile页面吗? (除了儿童路由'countries'

1 个答案:

答案 0 :(得分:2)

主应用程序路由器尝试匹配路由字符串时获取第一个dib,profile/skills匹配':continents/:countries'

':continents/:countries'相当于.+/.+作为路由正则表达式。它几乎匹配任何字符串,中间有一个斜杠。

您需要在该路线中添加'earth/:continents/:countries'之类的内容。将一些硬编码字符串添加到它的开头会使它停止如此无所不包。

相关问题