如何在不使用react router或window.location的情况下访问当前页面URL
我正在构建一个轻量级的 preact 小部件,它可以根据当前 url 为用户提供不同的表单。我不想使用 preact-router 因为它会影响父网站的路由。
所以我选择了 window.location。但我面临的问题是,当用户从一个页面内部导航到另一个页面时,除非有刷新,否则 window.location 不会更新当前 URL。
因此,如果我想将表格 1 发送给 /home 处的用户,将表格 2 发送给 /settings 处的用户。当用户在内部导航时,用户会获得相同的 /home 和 /settings 表单,并且仅在刷新时更改。
有人可以建议我一个轻量级的解决方案来解决这个问题吗?内存路由器适用于我的用例吗?
I've building a lightweight preact widget that gives users different forms based on current url. I don't want to use preact-router as it would affect the routing of the parent website.
So I went with window.location. But the issue, I'm facing is when users navigate internally from one page to another,unless there is refresh, window.location doesn't update the current URL.
Hence if i want to send form 1 to users at /home and form 2 to users at /settings. Users get the same form for both /home and /settings when users navigate internally and only change when they do a refresh.
Can someone suggest me a lightweight solution to fix this? Does in-memory router works for my use-case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论