我無法通過配置嵌套路由與新路由器導航。我得到的錯誤爲「錯誤:未捕獲(承諾):錯誤:無法匹配任何路線:'todos'」。我不知道我出了什麼問題。任何人都可以幫我解決這個問題嗎?提前致謝。無法使用嵌套路由導航 - angular2.rc3
回答
你需要把這樣的事情:
//our root app component
import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES, RouterConfig, Router} from '@angular/router';
import {LoginComponent} from './login';
import {TodosComponent} from './todos.ts';
export const AppRoutes: RouterConfig = [
{
path: "login",
component: LoginComponent,
name:"Login"
},
{
path: 'todos',
component: TodosComponent,
name:"Todos"
}
,
{
path: "",
redirectTo: "/todos"
},
]
@Component({
selector: 'my-app',
directives: [ROUTER_DIRECTIVES],
template: `
<a [routerLink]="['Login']">Login</a>
<a [routerLink]="['Todos']">Todos</a>
<router-outlet></router-outlet>
`,
})
那我可以在哪兒給孩子路線呢?我已經更新了我的運動員。現在它顯示了一些其他錯誤。你能檢查它並給我一個解決方案嗎? –
1)在您添加主要出發的應用程序是這樣的:
<...>
import { PLATFORM_DIRECTIVES } from '@angular/core';
<...>
bootstrap(<...>
, [APP_ROUTER_PROVIDERS , <...> ]);
<...>
2)然後定義你的應用的路由和導出它們的變種,APP_ROUTER_PROVIDERS,就像(首先你需要導入所有必要的組件 - 並且看到你有幾種方法來定義這些組件):
import { provideRouter, RouterConfig } from '@angular/router';
<...>
export const routes: RouterConfig = [
{ path: 'comp1', component: Component1 },
...Component1Routes, //if you want to have this in a separate file
{
path: 'comp2',
component: Component2,
'children': [
{ path: '', component: comp2 },
{ path: 'new', component: comp2new },
{ path: 'edit/:id', component: comp2edit }
]
}
];
<...>
export const APP_ROUTER_PROVIDERS = [
provideRouter(
routes
//, { enableTracing: true }
)
];
...
3)你還需要添加路由器指令在頂部組件:在所有子組件
import { ROUTER_DIRECTIVES } from '@angular/router';
4),你應該包括路由器& ActivatedRoute:
import { Router, ActivatedRoute } from '@angular/router';
5)在視圖您可以通過添加鏈接:
<a [routerLink]="['comp1']"> Comp 1</a>
,你可以在這裏找到一個正在運行的例子:http://embed.plnkr.co/ER0tf8fpGHZiuVWB7Q07/ 或http://plnkr.co/edit/Zd0qmavTzedtimImAgfQ?p=preview
我希望它能幫助
我已更新了我的運動員。現在它顯示了一些其他錯誤。我無法查看你的搶劫者。你可以檢查嗎? –
你現在可以檢查這個鏈接嗎?複製粘貼錯誤拳頭時間:D – Gabi
- 1. angular2無法使用路由器導航
- 2. Angular2新(RC1)路由器,嵌套路由器插座導航
- 3. Angular2中的無限嵌套路由
- 4. ANGULAR2-RC3路由:無法解析所有提供給路由器的參數:(?,?)
- 5. 在嵌套導航狀態提供嵌套路由
- 6. 路由到嵌套的導軌路由
- 7. Angular2嵌套路由不正確的URL
- 8. Angular2路由 - 手動網址導航
- 9. 陣營路由器V4嵌套的路線及方案導航
- 10. Angular2路由v3.0.0與深度嵌套路由
- 11. Angular2嵌套的模塊路由具有相同的路由
- 12. 默認路由參數Angular2:嵌套路由
- 13. Angular2嵌套子路由找不到路由匹配
- 14. 嵌套導航
- 15. 嵌套路由
- 16. Angular2路由器 - 無法使resetConfig工作
- 17. Angular 2路由 - 路由器RC3
- 18. 無法導航到aurelia中的子路由器路由
- 19. 如何導航與反應路由器嵌套組件4
- 20. Angular 2與新路由器的嵌套導航
- 21. Angular2中的HashLocationStrategy rc3
- 22. Rails的嵌套的路線導航
- 23. Angular2路由:使用路由導入子模塊+使其前綴
- 24. 不能得到嵌套航線使用陣營路由器
- 25. 導航路線問題Angular2
- 26. PHP嵌套導航
- 27. PyroCMS嵌套導航
- 28. Laravel嵌套導航
- 29. 淺嵌套導軌和路由:爲
- 30. 嵌套路由SAPUI5
我創建了一個[plunker(http://plnkr.co/edit/l30dbnSP8P6CCFfQmpfn?p=preview)它。請看看這個。 –