laravel:配置回退路由404(10.27.0)
一,相关文档:
https://learnku.com/docs/laravel/10.x/routing/14845#ad9737
二,php代码
在routes/web.php中添加以下代码:
|
1
2
3
4
5
6
7
8
|
//配置回退路由,起兜底作用Route::fallback(function () { $rs = [ 'code'=>404, 'msg'=>"访问地址错误", ]; return response()->json($rs);}); |
三,测试效果
默认:

配置后:

说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/10/17/laravel-pei-zhi-hui-tui-lu-you-404-10-27/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
四,查看laravel框架的版本:
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan --version
Laravel Framework 10.27.0

浙公网安备 33010602011771号