Skip to content

Commit e41308a

Browse files
authored
Update README.md
Add another usage if user do not want to overwrite redirector
1 parent b7c0a69 commit e41308a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,26 @@ interface Redirector
150150

151151
The `getRedirectsFor` method should return an array in which the keys are the old URLs and the values the new URLs.
152152

153+
## If you want to use `Route::fallback`
154+
155+
If you do not wish to overwrite the default redirector, or if you already have existing `Route::fallback` logic based on [laravel docs](https://laravel.com/docs/11.x/routing#fallback-routes), you can use this package as follow.
156+
In the bottom of your `web.php` file,
157+
158+
```php
159+
use Spatie\MissingPageRedirector\MissingPageRouter;
160+
//... Your other route
161+
162+
Route::fallback(function (Request $request) {
163+
$redirectResponse = app(MissingPageRouter::class)->getRedirectFor($request);
164+
165+
if ($redirectResponse !== null) {
166+
return $redirectResponse;
167+
}
168+
//... Your other logic
169+
});
170+
```
171+
You can adjust the priority of redirect base on your needs.
172+
153173
## Changelog
154174

155175
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

0 commit comments

Comments
 (0)