2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

URLに『#(ハッシュ記号)』がつかないようにしたい

Posted at

事象

画像の様にURLに『#(ハッシュ記号)』がついてしまう。
スクリーンショット 2019-10-21 22.19.52.png

環境

  • Rails: 5.2.3
  • vue: 3.10.0
  • vue-router: 3.1.3"

補足

VueRouterの生成時にmode:'history'を指定する方法や下記記事の方法が自分の環境では働かなかった。
Laravel + vue-routerでハッシュ記号(シャープ記号)をなくしてちゃんと動くようにする方法

解決策

下記のとおり、VueRouter生成時にmodeとhashとroutesの最後にpathのリダイレクトを追加する。


export default new VueRouter({
   mode: 'history',
   hash: false,
  routes: [
    {
      path: '/hoge',
      name: 'hoge',
      component: Hoge
    },
    中略
     { 
       path: '*', 
       redirect: '/' 
     }
  ],
})

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?