Phoenix 框架在路由到不同控制器时匹配不同的模式
Phoenix framework match different pattern on route to different controller
我需要将不同的路由模式匹配到不同的控制器。
示例:要将 http://localhost:4000/<_ANY_THING_>
匹配到 PageController@index
,我这样做:
get "/:page", PageController, :show
现在,我需要添加另一条仅匹配以下模式的路由:
http://localhost:4000/@<_ANY_THING_>
应该匹配 UserController@profile
我该怎么做?
包含 @
:
的路线没有什么不同
get "/@:user", UserController, :profile
请确保将其置于可能匹配的任何其他内容之上(例如您示例中的 catch all 路由。)
我需要将不同的路由模式匹配到不同的控制器。
示例:要将 http://localhost:4000/<_ANY_THING_>
匹配到 PageController@index
,我这样做:
get "/:page", PageController, :show
现在,我需要添加另一条仅匹配以下模式的路由:
http://localhost:4000/@<_ANY_THING_>
应该匹配 UserController@profile
我该怎么做?
包含 @
:
get "/@:user", UserController, :profile
请确保将其置于可能匹配的任何其他内容之上(例如您示例中的 catch all 路由。)