【程序目录】miss 路由添加注释

This commit is contained in:
sugar1569 2024-05-25 10:01:58 +08:00
parent 43a9598c28
commit cd9f49977f

View File

@ -1,31 +1,43 @@
<?php
use think\facade\Route;
/*
* 路由未匹配到任何路由时的处理函数
*/
Route::miss(function () {
// 获取当前请求的路径
$appRequest = request()->pathinfo();
// 如果路径为空,则设置应用名称为空字符串
if ($appRequest === null) {
$appName = '';
} else {
// 将双斜杠替换为单斜杠
$appRequest = str_replace('//', '/', $appRequest);
// 获取应用名称
$appName = explode('/', $appRequest)[0] ?? '';
}
switch (strtolower($appName)) {
// 如果应用名称为 admin、kefu 或 app,则返回对应的视图
case config('app.admin_prefix', 'admin'):
case 'kefu':
case 'app':
return view(app()->getRootPath() . 'public' . DS . config('app.admin_prefix', 'admin') . DS . 'index.html');
// 如果应用名称为 home,则根据请求类型返回不同的视图或重定向
case 'home':
// 如果是移动端访问
if (request()->isMobile()) {
return redirect(app()->route->buildUrl('/'));
} else {
return view(app()->getRootPath() . 'public' . DS . 'home' . DS . 'index.html');
}
// 如果应用名称为 pages,则返回 index.html 视图
case 'pages':
return view(app()->getRootPath() . 'public' . DS . 'index.html');
default:
// 如果不是移动端访问
if (!request()->isMobile()) {
// 如果请求类型为 PC,并且 home 目录存在且没有 mdType 参数,则返回 home/index.html 视图
if (is_dir(app()->getRootPath() . 'public' . DS . 'home') && !request()->get('mdType')) {
return view(app()->getRootPath() . 'public' . DS . 'home' . DS . 'index.html');
} else {