티스토리 뷰

Vue.js Router 현재 페이지 갱신하기

pilot376 2019. 6. 17. 15:17

Vue.js 라우터에서 페이지 이동 시 아래와 같이 push를 사용한다.

this.$router.push({name: 'Page', params: { key: 'aaa' }});

 

 

하지만, 같은 페이지에서 params 값만 갱신하면서 Router를 이동하려고 하면 작동하지 않는다.

// PageA에서 이동 시
this.$router.push({name: 'PageB', params: { key: 'aaa' }}); // 작동

// PageB에서 이동 시
this.$router.push({name: 'PageB', params: { key: 'bbb' }}); // 미작동

 

 

이 현상은 <router-view> 태그에 key 값을 추가하여 해결할 수 있다.

<router-view :key="$route.fullPath"/>

댓글