DEV Community

Brylie Christopher Oxley
Brylie Christopher Oxley

Posted on

4 2

Update "router-view" when Vue route changes

Sometimes, your Vue route will change, but will not trigger your router-view to update.

There is a simple way to tell the router-view, or any component, to update. Just bind the component key property to a reactive data source. In the case of router changes, you can bind the router-view to the $route.fullPath as follows:

<router-view :key="$route.fullPath"></router-view>
<!-- more verbose with v-bind:key -->
<router-view v-bind:key="$route.fullPath"></router-view>
Enter fullscreen mode Exit fullscreen mode

Now, any time the full path changes, the router-view will be updated.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay