①直接修改地址欄
localhost:4200/demo11
localhost:4200/demo12
②JS的方式
步驟一:import { Router } from '@angular/router'
步驟二:實例化 constructor ( private myRouter:Router) { }
步驟三:使用myRouter來實現導航 this.myRouter.navigateByUrl ( 'demo12') ;
③超鏈接 <a routerLink="demo12"></a>
④返回上一頁
步驟一:引入 import { Location } from '@angular/common'
步驟二:實例化 constructor (private myLocation:Location) { }
步驟三 :調用方法,返回上一頁的功能 this.myLocation .back();
⑤路由規則總結
當path為空,指定當前app默認加載第一個組件
當path為**,指定當前app在沒有成功的匹配到任何一個路由地址時,要訪問的組件(404/index)