# 路由的方法介紹「取得路由資訊、換頁、取用歷史紀錄、按鈕新增路由」 (7-8) ###### tags: `Vue`、`7. Router路由` 2022.3.10 ### 1. 取得路由資訊 (route、router) **(1) 取得route:此紀錄當下route相關資訊。** ``` this.$route ``` **應用範例,當在網址後加入變數,可以透過此查看數值。**  **(2) 取得GetRouter:此紀錄router中內建可使用的方法。** ``` this.$router ``` **總結果呈現**  ### 2. 換頁 (push、replace) ##### 位址:從根目錄#算起,假設要傳到 https://oldmoon/#/test/test2 網頁下,則地址處就改為/test/test2 **(1) push:換頁時會留下歷史紀錄。** ``` this.$router.push('位址'); ```  **(2) replace:換頁時不會留下歷史紀錄,假設從A頁用replace換到B頁,則從B頁回上一頁就不會回到A頁。** ``` this.$router.replace('位址'); ```  ### 3. 取用歷史紀錄 (go) **(1) 回上一頁** ``` this.$router.go(-1) ``` **(2) 回下一頁** ``` this.$router.go(1) ```  ### 按鈕新增路由 ``` create_router() { this.$router.addRoute({ path: '/預設路由地址', component: () => import('當前網頁與預設檔案的相對路徑'), }); alert('新增路由成功'); }, ```  結果 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up