vueのrouterはhistoryモード

1069 ワード

一、発生した問題1.ルーティングジャンプが機能しない(1)解決方法:router
Vue.use(Router)
export default new Router({
mode:'history',  //        
routes: [
     { path: '/', component: home},
     { path: '/content', component: Content },
        ]
})

mode:『history』と書くことに注意してください.
(2)理由:参考:vue router公式サイト構成https://router.vuejs.org/zh/guide/essentials/history-mode.htmlvue-routerデフォルトhashモード--URLのhashを使用して完全なURLをシミュレートし、URLが変更されるとページは再ロードされません.醜いhashが欲しくなければ、ルーティングのhistoryモードを使って、historyを十分に利用することができます.pushState APIは、ページ、すなわちvue routerがhash->historyモードを再ロードすることなくURLジャンプを完了する
2.historyに変換して必要なサポート(サーバのルーティング構成)が最初に分からなかったとき、私はすべての1級ルーティングを構成して、面倒なのでvue router公式サイトを参照して構成します.https://router.vuejs.org/zh/guide/essentials/history-mode.htmlnginx構成:
location / {
  try_files $uri $uri/ /index.html  @router;
}
//      404     @router
 location @router {
            rewrite ^.*$ /index.html last;
    }

Apacheなど他の方法であればvue router公式サイトを参照してください.https://router.vuejs.org/zh/guide/essentials/history-mode.html