Development/Vue.js
[Vue.js] push, replace, go
레오나르도 다빈츠
2022. 2. 14. 12:48
◽ router.push(...)
히스토리 스택에 추가되어 사용자가 뒤로가기를 하는 경우 이전 URL로 이동한다.
[방법 1.]
router.push('/main/home')
router.push({ path: '/main/home' })
router.push({ name: 'home', params: { username: 'vinch' } })
[방법 2.]
let username = 'vinch'
router.push(`/main/${username}`)
router.push({ path: `/main/${username}` })
router.push({ name: 'home`, params: { username } })
◽ router.replace()
url을 새 항목으로 대체한다. push와 달리 history가 쌓이지 않아 뒤로가기를 할 수 없다.
[방법 1.]
router.push({ path: '/main/home', replace: true })
[방법 2.]
router.replace('name')
◽ router.go(...)
// 1개의 기록 앞으로 이동한다. (=router.foward())
router.go(1)
// 1개의 기록 뒤로 이동한다. (=router.back())
router.go(-1)
// 3개의 기록 앞으로 이동한다.
router.go(3)
출처
Programmatic Navigation | Vue Router
Programmatic Navigation Aside from using to create anchor tags for declarative navigation, we can do this programmatically using the router's instance methods. Navigate to a different location Note: Inside of a Vue instance, you have access to the router i
router.vuejs.org
개인적으로 공부한 내용을 정리하는 블로그로
잘못된 개념을 게시하지않도록 주의하고 있으나 오류가 있을 수 있습니다.