> For the complete documentation index, see [llms.txt](https://liseen315.gitbook.io/laravel/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://liseen315.gitbook.io/laravel/bian-xie-apis/zi-ding-yi-404-xiang-ying/chu-fa-hui-tui-lu-you.md).

# 触发回退路由

如果要自定义当laravel捕获“未找到”异常时返回的路由，可以使用respondWithRoute()方法更新异常处理程序，如示例13-43所示。

{% code title="Example 13-43. Calling the fallback route when “not found” exceptions are caught" %}

```php
// App\Exceptions\Handler
public function render($request, Exception $exception) {
    if ($exception instanceof ModelNotFoundException && $request->isJson()) { 
        return Route::respondWithRoute('api.fallback.404');
    }
    return parent::render($request, $exception); 
}
```

{% endcode %}
