Невозможно прочитать свойство прослушивания undefined Vue-Router-next

https://codesandbox.io/s/vue-router-v4-reproduction-l5fzm?file=/index.html

Получение ошибки

Uncaught TypeError: невозможно прочитать свойство 'listen' undefined в createRouter (vue-router.esm-bundler.js: 2269) в main.js: 16 createRouter @ vue-router.esm-bundler.js: 2269 (анонимно) @ main .js: 16

Пример кода: как воспроизвести

const { createRouter, createWebHistory, createWebHashHistory } = VueRouter
const { createApp } = Vue

const Home = {
  template: `<div>home</div>`,
}

const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }

const router = createRouter({
  routes: [
    { path: '/', component: Home },
    { path: '/foo', component: Foo },
    { path: '/bar', component: Bar },
  ],
})

const app = createApp({})
app.use(router)

window.vm = app.mount('#app')

person Denis Tsoi    schedule 22.05.2020    source источник


Ответы (1)


Похоже, что ключ истории является обязательным параметром и разрешается в vue-router-next документы.

import { createRouter, createWebHistory } from 'vue-router'
// there is also createWebHashHistory and createMemoryHistory

createRouter({
  history: createWebHistory(),
  routes: [],
})
person Denis Tsoi    schedule 22.05.2020
comment
Я получаю, что createWebHistory - это не функция, и когда я печатаю, она не определена. В чем может быть проблема - person Abhi; 05.11.2020
comment
извините @Abhi, но вы должны включить коды и ящик, я не могу воспроизвести его со следующими кодами и ящиком codeandbox.io/s/vue-router-v4-reproduction-l5fzm?file=/ - person Denis Tsoi; 05.11.2020
comment
Nvm. Это произошло потому, что createWebHistory доступен из Vue router v4, а я использовал 3.3.7. - person Abhi; 06.11.2020