Angular 重定向到包含动态和静态部分的路径
请检查以下内容: plunkr可以工作,但实际上它不应该工作 以下是路线:Angular 重定向到包含动态和静态部分的路径,angular,angular2-routing,Angular,Angular2 Routing,请检查以下内容: plunkr可以工作,但实际上它不应该工作 以下是路线: export const routes: Routes = [ { path: '', redirectTo: 'projects', pathMatch: 'full' }, { path: 'projects', component: ProjectListComponent , children: [ { path: '', redirectTo: 'tests', pathMatch: 'f
export const routes: Routes = [
{ path: '', redirectTo: 'projects', pathMatch: 'full' },
{ path: 'projects', component: ProjectListComponent , children: [
{ path: '', redirectTo: 'tests', pathMatch: 'full' },
{ path: ':id/tests', component: TestsListComponent },
]
}
];
redirectTo
指向tests
路径,但tests
路径不存在
在我看来,重定向到的应该是:id/tests
或者路由器是否排除了动态:id
路径部分,而只考虑静态路径部分
我在::id/tests
上找不到匹配的信息,因为:id可以是任何字符串,甚至可以是空的。我无法复制。我根本找不到您的'
子路径被击中的位置。您的Tests
链接直接指向projects/1/Tests
。如果您有一个routerLink,其中只有/projects
作为路径,则会命中此重定向,但它没有按预期工作,无需复制任何内容,我只想回答关于动态/静态路径部分的问题;-)imo plunkr中的所有内容都是excepted only/projects/1抛出not found url异常,但这应该通过404路由解决。我已经看到了您的测试(默认)链接,但我不理解其目的;-)我真的不明白这个问题<代码>重定向到:“测试”
不应该工作。重定向需要被重定向到:'123/tests',,以匹配TestsListComponent
。你能不能试着更清楚地说明当前的行为是什么,预期的行为是什么?但我完全同意你!正如之前所说,重定向到:“测试”不应该起作用,但它确实起作用!我问为什么!?因为重定向到“:id/tests”无效!哈利路亚星期二:P