阻止 url 出现或修改当前地址栏值

Prevent url from appearing or modifying current address bar value

我有这个 vue js 脚本

const NotfoundComponent = {
    template: '<h1>Not found</h1>'
};

const HomeComponent = {
    template: '<h1>Home</h1>'
};

const AboutComponent = {
    template: '<h1>About</h1>'
};

const routes = [
    {
    path: '/',
    component: HomeComponent
  },
  {
    path: '/about',
    component: AboutComponent
  },
  {
    path: '*',
    component: NotfoundComponent
  }
];

const router = new VueRouter({
      mode: 'history',
      routes
});

new Vue({
    el: '#app',
    router
});

使用 vue-router。我在 spring mvc 应用程序内的 jsp 页面内 运行 vue js。我想正常加载由码头服务的 jsp 页面,并且只使用 vue js 路由器在页面内的组件之间导航。

我有路由器设置并在页面内工作,但是在 link 单击时,我不想要任何此 vue js links

<div id="app">
  <router-link to="/">home</router-link>
  <router-link to="/about">about</router-link>
  <router-link to="/something">no route</router-link>
  <router-view></router-view>
</div>

修改当前地址栏或向其追加任何新内容。

可以用vue js完成吗?

你想要'abstract' mode.

const router = new VueRouter({
      mode: 'abstract',
      routes
});

这需要您推送初始 URL:

// you main Vue instance
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App },
  mounted() {
    this.$router.replace('/') // added this
  }
})

CodeSandbox demo here.

请勾选下方link,您要使用摘要

https://jsfiddle.net/qpnaokhf/

const router = new VueRouter({
  routes,
  mode: 'abstract'
})