最简单的Angular Route hello world场景都跑不通的一个原因
生活随笔
收集整理的這篇文章主要介紹了
最简单的Angular Route hello world场景都跑不通的一个原因
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
我有一個最簡單的app Component:
@Component({selector: "app-root",template: `<div cxFocuses>Painful</div><a href="/custom2">Click me</a>` }) export class AppComponent {}我期望點擊了Click Me這個標簽之后,能跳轉(zhuǎn)到相對路徑/custom2.
在app.module.js里,定義一個route數(shù)組:
const CUSTOM_ROUTES: Routes = [{ path: "custom2", component: RouteDemoComponent } ];Routes是一個type alias,相當于Route[]:
而Route是一個interface:
https://angular.io/api/router/Route#description
我將RouterModule.forRoot返回的Module放到app.module.ts的imports區(qū)域之后:
瀏覽器訪問localhost:4200/custom2, 發(fā)現(xiàn)沒有跳轉(zhuǎn)到期望的Component里去。
經(jīng)過檢查,發(fā)現(xiàn)是因為我的application template里,缺少了router-outlet標簽的定義:
加上之后,問題解決:
更多Jerry的原創(chuàng)文章,盡在:“汪子熙”:
總結(jié)
以上是生活随笔為你收集整理的最简单的Angular Route hello world场景都跑不通的一个原因的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 花呗收钱服务费怎么算的
- 下一篇: Angular router-outle