【问题标题】:router raise error for any other route than slash路由器为除斜杠以外的任何其他路由引发错误
【发布时间】:2021-07-24 14:30:00
【问题描述】:

上下文

我在src/index.v有这个程序

import vweb

struct App {
    vweb.Context
}

["/"]
pub fn (mut app App) home_index() vweb.Result {
    return app.html("home")
}

["/about"]
pub fn (mut app App) about_index() vweb.Result {
    return app.html("about")
}

fn main() {
    vweb.run<App>(80)
}

然后我运行这个命令来编译它

v -o dist/index src/index.v

当我运行此命令时,服务器已启动

./dist/index

问题

当我浏览 http://localhost 时,我看到了主页文本,但是当我浏览 http://localhost/about 时,我看到控制台中打印了这个错误:

./dist/index
[Vweb] Running app on http://localhost:80
V panic: array.get: index out of range (i == -1, a.len == 0)
v hash: b3890e2
C.backtrace returned less than 2 frames

我注意到,如果我删除主路由代码块,不会引发错误(但我暂时不知道在找到“/”路由时如何显示响应)。

问题

有谁知道为什么会出现这个错误?

注意事项

我的 v 版本

v --version
V 0.2.2 b3890e2

我的操作系统版本

cat /etc/issue
Welcome to Alpine Linux 3.11

GCC 版本

gcc --version
gcc (Alpine 9.3.0) 9.3.0

【问题讨论】:

    标签: vlang


    【解决方案1】:

    这是框架 vweb 中的一个错误。 它正在PR #10001 中解决。

    【讨论】:

      猜你喜欢
      • 2021-01-10
      • 1970-01-01
      • 2018-01-01
      • 2012-08-02
      • 2018-03-30
      • 2019-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多