Saturday, 12 October 2019

Instantly redirect on application startup

I created a new Vue app with a base path. Due to the fact the app is embedded into another Vue app, this app doesn't render the router-view on startup. If you want to know more about how or why this app is embedded into another app, please have a look here:

mount Vue apps into container of main Vue app

and my own answer to this problem:

https://stackoverflow.com/a/58265830/9945420

When starting my application, it renders everything except the router-view. I want to redirect on startup by the given browser URL. This is my router config:

import Vue from 'vue';
import Router from 'vue-router';

import One from './views/One.vue';
import Two from './views/Two.vue';

Vue.use(Router);

const router = new Router({
    base: '/my-embedded-app/',
    mode: 'history',
    routes: [
        {
            path: '/',
            component: One,
        },
        {
            path: '/two',
            component: Two,
        },
    ],
});

router.replace(router.currentRoute.fullPath);

export default router;

I want the app to render the component Two when calling .../my-embedded-app/two. Unfortunately, router.replace always redirects to / (so the browser URL is .../my-embedded-app/). I debugged the router, and saw that the path is /, but I would expect it to be /two.

What might be wrong? Maybe I don't even need that redirect, and can solve the problem a more elegant way.



from Instantly redirect on application startup

No comments:

Post a Comment