angularcli 第八篇(router 路由)
阿新 • • 發佈:2018-09-03
url component module 針對 mage out 按鈕 png col
頁面有兩個按鈕(test1、test2),點擊這兩個按鈕,跳轉相應頁面~
註:創建一個帶路由模塊的項目:ng new project --routing
(下面針對新建項目時沒有帶路由,後邊再來新建路由)
1、新建兩個頁面 test1、test2(html、css、ts): ng g component test1
2、新建路由模塊app.routing.ts : ng generate module app-routing --flat --module=app
- 在 app.routing.ts 中 import 根組件、子組件路由組件等;
- 在 app.routing.ts 中 編寫路由路徑const routes;
3、在app.modules.ts中:
- 導入根組件路由組件,以及相應子組件(test1、test2) import { AppRoutingModules } from "./app/routing";
- 在 import:[......]中添加相應路由組件(routing)
- 初始化路由器imports: [ RouterModule.forRoot(routes) ], 基於瀏覽器的當前 URL 執行首次導航
3、在app.component.ts中添加相應的按鈕,以及路由路徑
angularcli 第八篇(router 路由)