如何重定向主页以'/{anything}'此路径,但重定向到profile.blader.php对于"/profile/{anything}"此路径?



我可以重定向到home.blade.php,以获取"/"此路径之后的任何内容。但是我需要重定向 profile.blade.php 文件,用于"/profile/{任何东西}"此路径。我该如何解决这个问题?

我已经使用波纹管代码重定向到home.blade.php

web.php...
-----------------------------
    Route::get('/{any}', function(){
        return view('home');
    })->where('any', '.*');

由于 OP 编辑问题而编辑:

你可以做这样的事情。请注意带有 {any?} 的部分。问号表示参数是可选的。因此,对/profile 的调用也将返回配置文件视图文件。如果不希望此行为,则应删除问号并仅写入{any}。

Route::get('/profile/{any?}', function (){
    return view('profile');
})->where('any', '.*');;
Route::get('/{any}', function (){
    return view('home');
})->where('any', '.*');

旧答案:

您可以简单地定义该路由。

Route::get('/test', function(){
    return view('test');
});
Route::get('/{any}', function(){
    return view('home');
})->where('any', '.*');

最新更新