# 路由的中間件
The routing has been implemented as middleware. We are still using[FastRoute](https://github.com/nikic/FastRoute)as the default router but it is not tightly coupled to it. If you wanted to implement another routing library you could by creating your own implementations of the routing interfaces.`DispatcherInterface`,`RouteCollectorInterface`,`RouteParserInterface`and`RouteResolverInterface`which create a bridge between Slim’s components and the routing library. If you were using`determineRouteBeforeAppMiddleware`, you need to add the`Middleware\RoutingMiddleware`middleware to your application just before your call run() to maintain the previous behaviour.
> 路由已作為中間件實現。我們仍然使用[FastRoute](https://github.com/nikic/FastRoute)作為默認路由器,但它并沒有與之緊密耦合。
> 如果希望實現另一個路由庫,可以創建自己的路由接口實現。`DispatcherInterface`,`RouteCollectorInterface`,`RouteParserInterface`and`RouteResolverInterface`在Slim的組件和路由庫之間建立了一座橋梁。如果您使用的是`Middleware\RoutingMiddleware`,那么您需要在調用run()之前將中間件路由中間件添加到您的應用程序中,以維護先前的行為。如果您使用的是`determineRouteBeforeAppMiddleware`,您需要在您的調用run()之前將`Middleware\RoutingMiddleware`中間件添加到您的應用程序中,以保持先前的行為。
## Usage
~~~php
<?php
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
// Add Routing Middleware
$app->addRoutingMiddleware();
// ...
$app->run();
~~~
- 開始
- 安裝
- 升級指南
- Web服務器
- 概念
- 生命周期
- PSR 7
- 中間件
- 依賴容器
- 實例 及通知和警告處理
- Request
- 請求方法
- 請求頭信息
- 請求主體
- 上傳的文件
- 請求幫助
- 路由對象
- Response
- 響應狀態
- 響應標頭
- 響應體
- 返回JSON
- 視圖模板
- 路由
- 創建路由
- 路由回調
- 路由策略
- 路線占位符
- 路由名
- 路由組
- 路由中間件
- 路由表達式緩存
- 容器識別解析
- 封裝中間件
- 路由的中間件
- 錯誤處理中間件
- 方法重寫的中間件
- 輸出緩沖中間件
- 內容長度中間件
- 擴展功能
- 以 / 結尾的路由模式
- 獲取當前路由
- 設置CORS
- 使用POST表單上傳文件
- 第三方組件
- slim-session
- auth
- slim-api-skeleton
- dir