Motomichi Works Blog

モトミチワークスブログです。その日学習したことについて書いている日記みたいなものです。

Vue2からVue3への移行作業で出た Error: Provide the "history" option when calling "createRouter()" を解決する

参照したページ

概要

vue-router を使っているアプリケーションを移行する際に発生するエラーです。

ブラウザのコンソールに出力されたエラー

Error: Provide the "history" option when calling "createRouter()"

解決方法

以下のように createRouter している箇所を

import { createRouter } from 'vue-router';
const router = createRouter({
    routes,
});

以下のように変更しました。

import { createRouter , createWebHashHistory } from 'vue-router';
const router = createRouter({
    history:createWebHashHistory(),
    routes
})

参照した2ページはそれぞれ、以下のメソッドを使用しています。

  • createWebHashHistory
  • createWebHistory

違いを調べてご自身のアプリケーションに適した方を使用してください。