A
A
Alexey2018-03-12 20:12:36
Vue.js
Alexey, 2018-03-12 20:12:36

Vue-router without creating a separate instance?

What is the correct way to write router paths directly in vue app without using new VueRouter ?

new Vue({
  el: "#app",
  data: {},
  router: router, //как вот тут правильно писать пути, без вынесения роутера за пределы
});

I tried to stupidly copy the object, as with other Vue properties, but apparently it doesn’t work that way, it constantly swears at something.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Pautov, 2018-03-12
@Azperin

new Vue({
  el: "#app",
  data: {},
  router: new VueRouter({
  routes: [
    // динамические сегменты начинаются с двоеточия
    { path: '/user/:id', component: User }
  ]
})
});

A
Alexey Yarkov, 2018-03-12
@yarkov Vue.js

How to build a house without starting? )))
That's right, no way.
By creating a new VueRouter instance, the output is not just an object that can be stupidly copied.
The output is an object that has associated methods and properties, without which nothing will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question