Itsik Mauyhas
Itsik Mauyhas

Reputation: 4002

Vue router - stay in the same url(without redirect)

I am using this simple-router example, but with my own components:

$( document ).ready(function() {

    const Home = { template: '<div id="login"><login-comp></login-comp></div>' };
    const Foo = { template: '<div>Foo</div>' };
    const router = new VueRouter({
      mode: 'history',
      routes: [
        { path: '/', component: Home },
        { path: '/foo', component: Foo }
      ]
    })
    new Vue({
        router,
        el: '#router',
        data: {
            msg: 'Hello World'
        }
    })

});

It works fine but as a change from one route to another the page redirect to my base url, for example my site is:

https://example.com/vue/index.jsp

after changing to /foo, the url changes to

https://example.com/foo

My index.jsp router:

<div id="router">
    <router-link to="/">/home</router-link>
    <router-link to="/foo">/foo</router-link>
    <router-view></router-view>
</div>

Thank's for any help.

Upvotes: 0

Views: 3049

Answers (1)

Daniel
Daniel

Reputation: 35724

That is how it's meant to work, when you set mode to history:

mode: 'history'

Remove that part, and you'll get a hash after your url, and it will work properly.

Upvotes: 1

Related Questions