Register 路由注册
let router = EngineRouter.default()
try routes(router)
services.register(router, as: Router.self)
Parameter
/users/:user_id
// Create a route for /users/:user_id
let user = Route(path: [.constant("users"), .parameter("user_id")], output: ...)
// Create a router and register our route
let router = TrieRouter(...)
router.register(route: user)
// Create empty Parameters to hold dynamic values
var params = Parameters()
// Route the path /users/42
_ = router.route(path: ["users", "42"], parameters: ¶ms)
// The params contains our dynamic value!
print(params) // ["user_id": "42"]
网友评论