mardi 4 septembre 2018

Redirect routes not redirecting to the correct routes

I'm building a dashboard interface in Vue with Vue-router using history mode. Everything is working fine when you navigate to the individual routes cooresponding to the sections of the dashboard (e.g. '/employees/dashboard/main', '/employees/dashboard/orders/all'). I'm trying to set up some redirects in the web.php file using Route::redirect('/here', '/there'). I want everything to go to my dashboard landing page route: '/employees/dashboard/main'. Some routes properly redirect and some don't depending on if a '/' is at the end of the URI or not.

'/employees' redirects to '/dashboard/main' (incorrect)

'/employees/' redirects to '/employees/dashboard/main' (correct)

'/employees/dashboard' redirects to '/employees/dashboard/main' (correct)

'/employees/dashboard/' redirects to '/employees/dashboard/dashboard/main' (incorrect)

web.php (snippet)

//Employee Routes
//below route was also giving the same result but I left here to show that    
//I've also tried it.
//Route::redirect('/employees', '/employees/dashboard/main');
Route::group(['prefix' => 'employees'], function() {
  Route::redirect('', 'dashboard/main', 308);
  Route::redirect('/', 'dashboard/main', 308);
  Route::redirect('/dashboard', 'dashboard/main', 308);

//catch-all route so vue router routes don't throw 404
Route::get('/dashboard/{any}', 'EmployeeController@showDashboard')
  ->where('any', '.*')
  ->name('employee.dashboard');
});

employee-dashboard.js (snippet)

const router = new VueRouter({
  mode: 'history',
  linkActiveClass: 'active',
  routes: [
    {path: '/employees/dashboard/main', component: Main},
    {
      path: '/employees/dashboard/orders',
      component: Orders,
      redirect: '/employees/dashboard/orders/active',
      children: [
        {path: 'all', component: FilteredOrders},
        {path: 'active', component: FilteredOrders},
        {path: 'completed', component: FilteredOrders}
      ]
    }
  ]
});

const dashboard = new Vue({
  el: '#dashboard',
  router
});

Then in dashboard.blade.php I have my router-links and router-view set up.

Any help will be greatly appreciated. Thanks.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2CgIofN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire