【问题标题】:All my routes redirect to home page我所有的路线都重定向到主页
【发布时间】:2018-05-13 05:25:05
【问题描述】:

我所有的 laravel 路由都不断重定向回主页。例如,当我转到localhost:8000/about 时,它停留在主页上,localhost:8000/about 出现在地址栏中,但我仍在主页上。我没有收到错误。此列表中的最后三 (3) 个将我重定向到主页:

<?php
//No auth needed to access these

Route::get('/course/detail/{id}', [
    'uses' => 'CourseController@show',
    'as' => 'course.detail'
]);

Route::get('/{pagenum?}', [
    'uses' => 'CourseController@showAll',
    'as' => 'courses'
]);

Route::get('/instructor/detail/{id}', [
    'uses' => 'InstructorController@showDetail',
    'as' => 'instructor.detail'
]);

Route::get('/about', function(){
    return view('frontend.about');
})->name('about');

Route::get('/contacts', function(){
    return view('frontend.contacts');
})->name('contacts');

Route::get('/search', [
    'uses' => 'CourseController@search',
    'as' => 'courses.search'
]);

我有以上这些路线,您需要在访问之前对其进行身份验证,并且我可以在登录后访问它们。您无需登录即可访问上述路线。从我上面提到的六 (6) 个中,我可以访问前三 (3) 个而不被重定向。其他三 (3) 个将我重定向到主页,没有错误

我对 Laravel 并不陌生,这些路线以前是有效的。这种重定向的原因可能是什么?

【问题讨论】:

  • 你使用的是 vue js 还是 angular ?如果是这样,他们可能与他们的路线冲突
  • 不,我没有使用 vue 或 angular @Hussein
  • 哦,我猜我找到了你的问题,将最后 3 条路由移到 /{pagenum?} 路由上方,因为 pagenum 路由非常通配(:
  • @num8er 成功了,谢谢

标签: laravel laravel-5.3


【解决方案1】:

您对定义路线的顺序有疑问。

你已经定义了:

Route::get('/{pagenum?}', [
    'uses' => 'CourseController@showAll',
    'as' => 'courses'
]);

就像/anything-that-comes-here

前缀/ 的其他路由定义正被它阻止。

所以只需移动它上面的最后 3 条路线:

Route::get('/about', function(){
    return view('frontend.about');
})->name('about');

Route::get('/contacts', function(){
    return view('frontend.contacts');
})->name('contacts');

Route::get('/search', [
    'uses' => 'CourseController@search',
    'as' => 'courses.search'
]);

Route::get('/{pagenum?}', [
    'uses' => 'CourseController@showAll',
    'as' => 'courses'
]);

【讨论】:

    【解决方案2】:

    第二条路线是你必须放在最后的问题:

    Route::get('/{pagenum?}', [
        'uses' => 'CourseController@showAll',
        'as' => 'courses'
    ]);
    

    【讨论】:

      猜你喜欢
      • 2015-06-26
      • 2023-04-02
      • 1970-01-01
      • 2013-10-21
      • 2013-08-22
      • 1970-01-01
      • 2018-03-28
      • 2016-07-12
      • 2022-08-14
      相关资源
      最近更新 更多