为 router.ex 中的参数匹配 URL 的其余部分

Matching the rest of a URL for parameters in router.ex

如何匹配 router.ex 中的路径结尾,例如下面的那个。路径结构不固定,可能有one/two/three层或更多层

www.example.com/first/second/third 

www.example.com/first/second

通常你可以做一个 get "/:first" 但它只会捕获第一个作为 params["first"]

基于https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/router.ex

你可以做一个

get "/first/*anything"

您可以在控制器中调用 params["anything"] 来获取剩余的路径。

编辑:如果您的路径是 /first/second/thirdparams["anything"] 将 return 列出 ["second","third"]