序文:
ここでは、vue2.0およびvue3.0でルーターをハッシュまたは履歴に変更する方法を分析して要約します。
view2.0
歴史:
const router = new VueRouter({
mode: 'history',
routes: [...]
})
ハッシュ:
const router = new VueRouter({
mode: 'hash', //或者把这句话注释,默认就是hash
routes: [...]
})
vue3.0
履歴:引入-createWebHistory
import { createRouter, createWebHistory} from 'vue-router';
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
});
ハッシュ:-createWebHashHistoryを紹介します
import { createRouter, createWebHashHistory } from 'vue-router';
const router = createRouter({
history: createWebHashHistory(),
routes
});