Laravel Vue VueRouter history mode Laravel Vue VueRouter history mode laravel laravel

Laravel Vue VueRouter history mode


You need to set the base value to tell Vue Router what the base URL of your application is. In your case you can set it dynamically using the locale value.

For example, in your Blade template you could have the following script to set the locale value on the JavaScript window object:

<script>    window._locale = "{{ app()->getLocale() }}";</script> 

And then you can set the base value to the locale when creating your router:

router: new VueRouter({  mode: 'history',  base: `/${window._locale}/`,  routes})


Very simple way is too Accept the locale in Vue router too. So your route would be like this:

export const routes = [    {        path: '/:locale',        children: [        {            path: '',            component: require('./components/Page/HomePage').default,        },        {            path: 'product',            component: require('./components/Page/Product/ProductPage').default,        },        ]    }];

just be sure for children route dont put '/' in begining because its remove locale