search

Home  >  Q&A  >  body text

router.push not working - Stack Overflow

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

高洛峰高洛峰2707 days ago718

reply all(3)I'll reply

  • phpcn_u1582

    phpcn_u15822017-06-26 10:55:18

    Change the one below to routes.push

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-06-26 10:55:18

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

    reply
    0
  • 天蓬老师

    天蓬老师2017-06-26 10:55:18

    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

    reply
    0
  • Cancelreply