在app下新建了两个模块,单独配置路由,但是不起作用,使用默认路由可以访问到

condy

问题描述

在app下新建了两个模块backend,frontend,分别设置了route路由,在config/route中以引入两个模块的路由文件route,默认路由已关闭,但是在访问的时候无法访问到,直接报404.

程序代码或配置

config/route配置
/**
 * 引入backend模块路由
 */
require_once app_path('backend/config/route.php');

/**
 * 引入frontend模块路由
 */
require_once app_path('frontend/config/route.php');

/**
 * 关闭默认路由
 */
Route::disableDefaultRoute();

backend/config/route.php路由文件

Route::group(function () {
 $path = app_path() . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'route';
    //echo "Loaded route file: $path\n";
    //具体地址:\app\backend\route
    if (is_dir($path)) {
        $files = scandir($path);
        foreach ($files as $file) {
            if ($file !== '.' && $file !== '..' && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
                require $path . DIRECTORY_SEPARATOR . $file;
            }
        }
    }
});

具体路由文件

Route::group('/backend', function () {
    Route::group(function () {
        Route::post('/system/login', [\app\backend\controller\LoginController::class, 'login'])->name('登录');
        Route::post('/system/logout', [\app\backend\controller\LoginController::class, 'logout'])->name('注销');
        Route::get('/system/captcha', [\app\backend\controller\LoginController::class, 'captcha'])->name('验证码');
        Route::get('/system/image', [\app\backend\controller\LoginController::class, 'image'])->name('登录背景图');
    });

})->middleware([
    app\middleware\AllowCrossOriginMiddleware::class,

]);

Route::group('/system', function () {

})->middleware([
    app\middleware\AllowCrossOriginMiddleware::class,
    app\backend\middleware\AdminAuthTokenMiddleware::class,
    app\backend\middleware\AdminAuthPermissionMiddleware::class,
    app\backend\middleware\AdminLogMiddleware::class,
    // app\backend\middleware\RouteRestrictionMiddleware::class,//演示系统拦截不允许操作路由
]);

重现问题的步骤

这里使用链接:
http://127.0.0.1:8787/backend/system/captcha
http://127.0.0.1:8787/system/captcha
均获取不到结果,返回404,
使用默认路由:http://127.0.0.1:8787/backend/login/captcha可以获取到

操作系统环境及workerman/webman等具体版本

"php": ">=7.2",
"workerman/webman-framework": "^1.5.0",

64 1 0
1个回答

Route::group(function(){
  require 文件;
});

Route::group('/system', function () {
    空的
})->middleware([...]);

手册里没有这样的用法

  • 暂无评论
×
🔝