重定向路由未重定向到正确的路由

时间:2018-09-04 14:49:55

标签: laravel-5

我正在Vue中使用历史记录模式在Vue中构建仪表板界面。当您导航到对应于仪表板各部分的各个路线时,一切工作正常(例如'/ employees / dashboard / main','/ employees / dashboard / orders / all')。我正在尝试使用Route :: redirect('/ here','/ there')在web.php文件中设置一些重定向。我希望所有内容都进入我的仪表板登录页面路线:“ / employees / dashboard / main”。有些路由可以正确重定向,而有些则不取决于URI末尾是否有一个'/'。

'/员工'重定向到'/ dashboard / main'(不正确)

'/ employees /'重定向到'/ employees / dashboard / main'(正确)

'/ employees / dashboard'重定向到'/ employees / dashboard / main'(正确)

'/ employees / dashboard /'重定向到'/ employees / dashboard / dashboard / main'(不正确)

web.php (摘要)

//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 (摘要)

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
});

然后在dashboard.blade.php中,我已经设置了路由器链接和路由器视图。

任何帮助将不胜感激。谢谢。

编辑: 更奇怪的是,当我注释掉web.php中的所有Route :: redirect条目,运行php artisan route:clear,然后重新启动php artisan serve,然后转到/ employees,它仍然将我重定向到错误的路由( / dashboard / main)。

1 个答案:

答案 0 :(得分:0)

我发现了重定向错误的原因。浏览器缓存重定向,由于某种原因,它将使用该重定向,而不是使用routes / web.php文件中的更新的重定向路由。要在Firefox中清除此缓存,请执行以下操作:进入历史记录菜单,右键单击laravel项目中的页面之一,然后单击“忘记此站点”。现在它将使用您的路由文件中更新的重定向路由。

我也将重定向更改为:Route :: redirect('/ employees','/ employees / login');因为我正在使用Laravel的Auth脚手架,并且将其设置为登录后重定向到仪表板的主页。

在这里找到此解决方案: https://superuser.com/questions/467999/clear-301-redirect-cache-in-firefox#661767

相关问题