router.push not working - Stack Overflow
高洛峰
高洛峰 2017-06-26 10:53:18
0
3
714

import Vue from 'vue'
import App from './App'
import VueRouter from './router'

Vue.config.productionTip = false

VueRouter.push('/goods')

/ eslint-disable no-new /
new Vue({
el: '#app',
router: VueRouter,
template: '<App />',
components: { App }
})

Here VueRouter.push('/goods') is valid

import Vue from 'vue'
import Router from 'vue-router'
import goods from '../components/goods/goods'
import seller from '../components/seller/ seller'
import ratings from '../components/ratings/ratings'

Vue.use(Router)

/ eslint-disable no-new /
const routes = [
{ path: '/seller', component: seller },
{ path: '/ratings' , component: ratings },
{ path: '/goods', component: goods }
]

Router.push('/goods')

export default new Router({
routes
})

The .push here is invalid
I don’t quite understand the problem here

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
phpcn_u1582

Change the one below to routes.push

仅有的幸福

Change the one below to routes.push({path:'/goods'})

Peter_Zhu

Router.push('/goods') can only be called after the route is successfully configured and referenced in the required page. The question is: your route outputs routes, so you must import routes where you need to use them, that is, import routes from '/routing configuration file'. Finally, you can use the relevant api in the page after the routes are introduced

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template