16. Vue JS/Vue 2
08. Vue 2 - Router 현재 페이지 갱신
THE HEYDAZE
2020. 9. 23. 06:53
OS | Windows 10 Home 64bit 버전 1903 (OS 빌드 18362.836) |
Vue | 2.5.13 |
# 방법 1
# 방법 2
[router.js]
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomePage from "../views/HomePage";
/** 같은 페이지에서 같은 페이지로 $router.push 한 오률를 처리함 (ex : 홈페이지에서 홈 로고를 클릭한 경우) */
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(() => {
return window.location.reload()
})
};
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'home',
component: HomePage,
}
]
const router = new VueRouter({
mode: 'history',
routes,
})
export default router