gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:16:43 26 4
gpt4 key购买 nike

如何匹配 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/thirdparams["anything"] 将返回 ["second","列表第三”]

关于elixir - 匹配 router.ex 中参数的 URL 的其余部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34411289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com