扣丁學堂HTML5培訓之Angular RouterLink花式跳轉
今天扣丁學堂給大家介紹一下關于HTML5視頻教程之AngularRouterLink花式跳轉的相關資料,文中通過示例代碼介紹的非常詳細,下面我們一起來一下吧。
除了使用Router的navigate()方法切換路由,Angular2還提供了一個指令用來將一個DOM對象增強為路由入口:
@View({ directives:[RouterOutlet,RouterLink] template:`<nav> <brouter-link="video">video</b>| <brouter-link="music">music</b> </nav> <router-outlet></router-outlet>` })
RouterLink指令為宿主DOM對象添加click事件監聽,在觸發時調用Router的navigate()方法進行路由。
不過本文主要介紹的是關于Angular之RouterLink花式跳轉的相關內容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧。
routerLink本身支持兩種寫法:
<arouterLink="detail"> </a> <a[routerLink]="['detail']"> </a>
routerLink的值有哪些寫法,又有什么區別呢?
假設當前路由為
`http://localhost:4200/#/doc/license`
寫法1:絕對路徑/+路由名字
<!--跳到http://localhost:4200/#/doc/license--> <a[routerLink]="['/doc/demo']">跳呀跳</a> <!--跳到http://localhost:4200/#/demo--> <a[routerLink]="['/demo']">跳呀跳</a>
那么url是http://localhost:4200/#/doc/demo上跳轉,即http://localhost:4200/#/+你要跳轉的絕對路徑。
寫法2:一個路由名字路由名字
<a[routerLink]="['demo']">跳呀跳</a>
那么url是http://localhost:4200/#/doc/license/(demo),即http://localhost:4200/#/doc/license+你要跳轉的絕對路徑,這時候它會給你的路由加些東西變成/(demo),跳轉不了。
寫法3:相對路徑../路由名字
<a[routerLink]="['../demo']">跳呀跳</a>
那么url是http://localhost:4200/#/doc/demo,即http://localhost:4200/#/doc+你要跳轉的相對路徑。它會從上一級開始尋找。
寫法4:./路由名字,即現在的路由+你寫的要跳去的路由
<a[routerLink]="['./demo']">跳呀跳</a>
那么url是http://localhost:4200/#/doc/license/demo上,即http://localhost:4200/#/doc/license+你要跳轉的相對路徑。它會從當前路由的下一級開始尋找此匹配的路由進行跳轉。
以上就是關于HTML5視頻教程之AngularRouterLink花式跳轉的詳細介紹,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,最后想要了解更多html5培訓課程相關內容的小伙伴可以登錄扣丁學堂官網查詢,扣丁學堂不僅有專業的老師和與時俱進的課程體系,還有大量的html5視頻教程供學員觀看學習,想要學習html5的小伙伴快選擇專業的html5在線學習機構扣丁學堂學習吧。扣丁學堂H5技術交流群:692172929。微信號:codingbb
*博客內容為網友個人發布,僅代表博主個人觀點,如有侵權請聯系工作人員刪除。