I use Vue and VueRouter (and also Vuex but it is not the case here) in my project. Imagine i have 5 files:
- main.js - stores all components definitions, imports them from external files and so on.
- App.vue - it is main component that stores all other
- routes.js - stores all the routing definitions
- login.vue - stores login component (login page)
- content.vue - stores page component
(quite simplified version but you surely get the idea).
Now if i open my path '/' it should reroute me to '/login' page if i am not logged in and to '/content' when i am logged in. Nothing special here. Now my page works as intended (almost). If I enter in my browser '/content' it tries to render '/content' component with default data (ie userId = -1), then immediately it reroutes me to '/login' page. The '/content' shows just for a second. And it is my problem. I would like to reroute to '/login' without earlier rendering '/content' with default data.
It is obvious that it tries to render '/content' - maybe from cache or something, but since rerouting is my first command in created() it should not mount /content component in app component, but /login.
Any idea how to prevent it? I am aware that i do not attach any code, but i hope it wont be necessery for you to understand the problem and advice any solution because it would need cutting and simpliding a lot of code.