18
rated 0 times
[
22]
[
4]
/ answers: 1 / hits: 5582
/ 4 Years ago, wed, july 8, 2020, 12:00:00
The vue-router is functioning fine but we would like to push a route in another file. Some code to clarify:
// src/router/index.ts
import { route } from 'quasar/wrappers'
import VueRouter from 'vue-router'
import routes from './routes'
export default route(function ({ Vue }) {
Vue.use(VueRouter)
const Router = new VueRouter({
scrollBehavior: () => ({ x: 0, y: 0 }),
routes,
mode: process.env.VUE_ROUTER_MODE,
base: process.env.VUE_ROUTER_BASE,
})
return Router
})
It would be great to be able to adjust the route in another file like this:
// src/services/auth/authService.ts
import router from 'src/router'
if (router.currentRoute.path === '/login') {
console.log('authService push to /');
router.push('/')
}
But this throws the error:
TS2339: Property 'currentRoute' does not exist on type 'RouteCallback'.
We're probably not exporting/importing the router correctly.
More From » typescript