我无法让帕格访问window.local.href
我已经读过关于它的插值,在GitHub上搜索了帕格文件,这里是SO。仍然无法将其显示在当前URL的href属性中。
我已经在y项目的几个模板中成功地使用了变量,有时是在一些尝试和错误之后。
但我被困在这里了。试图用暴力逼我离开这里:
script.
currentURL = window.location.href
console.log(currentURL) // Works as expected
console.log(window.location.href) // Works as expected
pre= currentURL // undefined
pre= window.location.href // error because everything is undefined
input.sample(type='button', value="alert href", onclick="alert(window.location.href)") // Works as expected
a(href = 'https://url-to-append-it-to.com/?status=!{window.location.href}')
a(href = 'https://url-to-append-it-to.com/?status=#{window.location.href}')
a(href = 'https://url-to-append-it-to.com/?status=${window.location.href}')
a(href = `https://url-to-append-it-to.com/?status=${currentURL}`)
a(href = `https://url-to-append-it-to.com/?status=#{window.location.href}`)
a(href = `https://url-to-append-it-to.com/?status=!{window.location.href}`)
- currentURL = window.location.href // Cannot read property 'location' of undefined
a(href=${window.location.href}) // Unexpected token
a(href=#{window.location.href}) // Unexpected character '#'
a(href=window.location.href) // Cannot read property 'location' of undefined
a(href=${currentURL}) // Unexpected token
a(href=#{currentURL}) // Unexpected character '#'
a(href=currentURL) // links to undefined
a(href=${window.location.href}) // Unexpected token
window.location.href
像这样的
locals.currentURL
没有运气。
现在,我决定从routes文件中传递:
currentLocation: req.protocol + "://" + req.headers.host + req.url
使用方法如下:
a(href= `https://url-to-append-it-to.com/?status=${currentLocation}`)
这工作得很好,但我想知道当我试图从帕格请求本地浏览器变量时遗漏了什么。
我假设脚本标记在呈现帕格时确实在客户端运行,但是可能我遇到问题的变量在呈现过程中运行了一半?我不知道。