Vue JS Router: Reload page on redirect
P粉087074897
P粉087074897 2023-10-26 11:53:46
0
2
714

I have an application with Login.vue and Home.vue files. Because I'm converting an admin HTML website to a vue 3 application, my javascript only works on page reloads. When creating the application I chose to add a router for the SPA, maybe I shouldn't have done that. So far the view is working except when I redirect from login to home page without reloading. Since it won't reload, my navigation bar or any functionality that relies on JS won't work. How to redirect from login to home page via page reload? Currently I have the following code but it still doesn't work.

this.$router.push({
      path: "/admin/home",
      reload: true
    });


P粉087074897
P粉087074897

reply all(2)
P粉543344381

Vue Router does not reload the page when navigating to a new URL.

You can try this code for your problem:

const url = new URL('/admin/home', window.location.origin)
window.location.href = url.toString()

Hope this helps

P粉009828788

You can use this.$router.go() with empty parameters to reload the page. Combined with this.$router.push({ path: '/admin/home' }) you can achieve this without using normal JS functionality.


    
sssccc

Note how I use .then after $router.push(). Without then, the page would reload too quickly, leaving no time to change routes.

As a bonus, it lets you use all the functionality of $router.push (e.g. using parameters like { name: 'home' } etc.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template