Swift Vapor 4中的自定义叶标记

Swift Vapor 4中的自定义叶标记,swift,xcode,vapor,leaf,Swift,Xcode,Vapor,Leaf,我将遵循本教程: https://theswiftdev.com/custom-leaf-tags-in-vapor-4/ 由于不清楚,我尝试将struct PathTag放入configure.swift,然后放入routes.swift struct PathTag: LeafTag { static let name = "path" func render(_ ctx: LeafContext) throws -> LeafData { let

我将遵循本教程:

https://theswiftdev.com/custom-leaf-tags-in-vapor-4/
由于不清楚,我尝试将struct PathTag放入configure.swift,然后放入routes.swift

struct PathTag: LeafTag {

    static let name = "path"

    func render(_ ctx: LeafContext) throws -> LeafData {
        let value = ctx.request?.url.path ?? ""
        return .string(value)
    }
}
我使用的是Vapor 4,我的GET和POST路由在localhost:8080上运行正常,但leaf是新的。他说:“我们可以使用这个新创建的path标记,基于当前路径构建一个URL,并使用一些额外的查询参数,如:#path()?foo=bar。”

不确定他的意思,我在浏览器中尝试了以下操作:

http://localhost:8080/path?foo=bar

假设您有一个Vapor应用程序在
localhost
上运行,并且您设置了一个路由,例如:

http://localhost:8080/a/route/to

在为该路线渲染的
.leaf
文件中,如果放置:

然后,当您单击该链接时,它会将您带到:

http://localhost:8080/a/route/to/somewhere

我将所有自定义标记保存在一个单独的
.swift
文件中,只需将代码注册到
configure.swift