VueJS 路由器重定向到服务器路径

VueJS Router redirect to server path

我正在使用以下路由器设置:

export default new Router({
  mode: 'hash',
  linkActiveClass: 'open active',
  scrollBehavior: () => ({ y: 0 }),
  routes: [
    {
      path: '/',
      ....

在 .vue 文件中声明了以下注销函数:

logout () {
  this.$router.push('/logout')
}

当我 运行 应用程序时,路径是:

www.mydomain.com/app#/router_paths

所以当我运行上面的注销功能时,我被重定向到:

www.mydomain.com/app#/logout

我尝试使用:

<b-dropdown-item ><i class="fa fa-lock"></i> <a href="logout">Logout</a> </b-dropdown-item>

虽然硬编码适用于本地和服务器,但我将鼠标悬停在 link 上,它显示

www.mydomain.com/logout

但是当我点击它时没有任何反应 - 即我没有被重定向

如何告诉路由器重定向到

www.mydomain.com/logout

(不只是在代码中硬编码 - 因为我想 运行 在本地和已部署的实例上)

window.location.replace('/logout')

The replace() method replaces the current document with a new one.

来自 w3.

logout () {
  window.location.replace('/logout');
}

然后使用

<button v-on:click="logout">Logout</button>