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
Change the one below to routes.push
Change the one below to routes.push({path:'/goods'})
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