Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue-router redirect to default path issue

I want to default to a specific page when user navigates to the root path ie when used goes to myapp.com I want to redirect them to myapp.com/defaultpage

My current code is

index.js

import Full from '../containers/Full' import DefaultView from '../views/DefaultView'  export default new Router({   mode: 'history',   linkActiveClass: 'open active',   scrollBehavior: () => ({ y: 0 }),   routes: [     {       path: '/',       redirect: '/defaultview',       name: 'home',       component: Full,       children: [         {           path: '/defaultview',           name: 'defaultview',           component: DefaultView         },         {           path: '*',           component: NotFoundComponent         }     } ]}) 

As it is when user goes to myapp.com I get a '404 page not found' - ie the NotFoundComponent. Only when I type in myapp.com/defaultview can I get to the correct page.

Any ideas?

like image 555
proximacentauri Avatar asked May 19 '17 02:05

proximacentauri


1 Answers

Try this code:

routes: [     {       path: '/',       redirect: '/defaultview'     },     {       path: '/defaultview',       name: 'defaultview',       component: DefaultView     },     {       path: '*',       component: NotFoundComponent     } ] 
like image 85
Adriano Resende Avatar answered Sep 21 '22 00:09

Adriano Resende