简体   繁体   English

具有实际URL的单页应用程序

[英]Single-Page Application with Real URLs

I'm not supporting clients that can't run JavaScript. 我不支持无法运行JavaScript的客户端。

I want my URL paths to look like /settings , not /#settings , ie, no hash or fragment identifiers. 我希望我的URL路径看起来像/settings ,而不是/#settings ,即没有哈希或片段标识符。

I understand how to intercept a click event with JavaScript. 我了解如何使用JavaScript拦截点击事件。

But, what should the server do? 但是,服务器应该怎么做? Should the server just reply to every page, eg, / , /settings , /profile , etc., with the same exact HTML file? 服务器是否应该仅使用相同的确切HTML文件答复每个页面,例如//settings/profile等?

Then, after the page loads, the JavaScript will decide which parts of the HTML to display based on the location's path? 然后,在页面加载后,JavaScript将根据位置路径决定要显示HTML的哪些部分?

You need to use pushState. 您需要使用pushState。 Here's a link to MDN on how to do it. 这是有关MDN的链接。

https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_pushState()_method https://developer.mozilla.org/zh-CN/docs/Web/API/History_API#The_pushState()_method

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

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