如何匹配 router.ex 中路径的末尾,如下所示。路径的结构不固定,可以有一层/两层/三层或更多层
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"
您可以在 Controller 中调用 params["anything"]
来获取路径的其余部分。
编辑:如果您的路径是 /first/second/third
,params["anything"]
将返回 ["second","列表第三”]
关于elixir - 匹配 router.ex 中参数的 URL 的其余部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34411289/