简体   繁体   English

如何使用 JavaScript 刷新单页应用程序?

[英]How to refresh single page application with JavaScript?

I have a single page application, and I want to reload, but whenever I run window.location.reload(true);我有一个单页应用程序,我想重新加载,但是每当我运行window.location.reload(true); , it refreshes to the homepage. ,它刷新到主页。 For example, if I run it from www.mywebsite.com/test/1 , it will open www.mywebsite.com , I simply want it to refresh to www.mywebsite.com/test/1 , and I want it to happen from server, not from cache.例如,如果我从www.mywebsite.com/test/1运行它,它将打开www.mywebsite.com ,我只是希望它刷新到www.mywebsite.com/test/1 ,我希望它发生来自服务器,而不是来自缓存。 Any ideas how to do it with pure JS?任何想法如何用纯JS做到这一点?

Try尝试

window.location = 'www.mywebsite.com/test/1'

It will still reload the page, but as long as your JS redraws based on the URL it should work.它仍然会重新加载页面,但只要您的 JS 基于 URL 重绘它就应该可以工作。

IMHO a single page app should never call reload.恕我直言,单页应用程序永远不应该调用重新加载。 You just draw and clear elements on the page.您只需在页面上绘制和清除元素。

你试过简单的 location.reload() 吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM