import { Module } from 'vuex' ; import { RootState } from '@/store/types' ; import VueRouter from 'vue-router' ; export interface RouterState { router : VueRouter | undefined ; lastUrl : string ; } const initialState = { router : undefined , lastUrl : '/' } ; const getters = { currentPath ( state ) { if ( ! state . router ) { return '' ; } return state . router . currentRoute . path ; } } ; const mutations = { setRouter ( state , router_ ) { state . router = router_ ; } , replace ( state , url ) { state . lastUrl = url ; if ( state . router ) { state . router . replace ( url ) ; } } } ; const router = { namespaced : true , state : initialState , getters , mutations } ; export default router ;