# 路由重写

如果想针对某个已有的路由从 Controller, Service, Repository, View 完全重写, 可以在插件对应的路由直接设置相同路由进行覆盖。 比如想在插件直接重写首页, 可以在插件前台路由 /plugins/插件/Routes/shop.php 这样定义:

Route::get('/', function (){
    return '插件自定义首页';
})->name('home.index');

img.png

刷新首页,效果如下:

img.png

当然,也可以定义为插件内 Controller 方法, 比如

Route::get('/', [CustomController::class, 'home'])->name('home.index');

然后再在插件内按照 Laravel MVC 方式实现 CustomController 以及对应方法即可