gpt4 book ai didi

javascript - 具有任意文本的主干路由

转载 作者:行者123 更新时间:2023-12-02 22:23:47 25 4
gpt4 key购买 nike

我有一个页面被从外部重定向到主干代码库。它有两个参数:

  • ID:整数
  • CODE:随机可打印的 ascii 字符串(无 #&?,但可以包含 -并且始终包含 /)

不确定CODE参数是否经过%编码。我想如果需要的话我可以让他们控制它。但目前的问题只是匹配。

我是一名维护程序员,最初不是我的应用程序,所以只是尝试编写“适合”的代码。

大多数现有路由仅采用单个 ID。例如

"account-edit-:accountId"    : "accountEditRoute"

但是我如何将两个参数传递到我的进程路由中。我尝试过:

"process-:id-:code"    : "processCode"
"process-[^-]*-:code" : "processCode"
"process-:id/:code" : "processCode"
"process-:id/*" : "processCode"

我的代码处理程序如下:

processCode: function(id, code) {
...
}

我总是收到未知的路由处理程序。那么我该如何匹配上面的内容。

抱歉,如果这是一个愚蠢的问题 - 但他们(明智地)通常不会让我接近前端,所以对我来说都是新的。

最佳答案

我相信你必须使用Router-route来做到这一点带有正则表达式的选项。路由哈希只能匹配简单的模式。

Manually create a route for the router, The route argument may be a routing string or regular expression. Each matching capture from the route or regular expression will be passed as an argument to the callback.

initialize: function(options) {

// Matches #page/10, passing "10"
this.route("page/:number", "page", function(number){ ... });

// Matches /117-a/b/c/open, passing "117-a/b/c" to this.open
this.route(/^(.*?)\/open$/, "open");

},

open: function(id) { ... }

关于javascript - 具有任意文本的主干路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59132396/

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