简体   繁体   English

推送状态-如何更新相对链接

[英]Push State - How to update relative links

I want to use push state to update the url when loading ajax content. 加载ajax内容时,我想使用推送状态更新URL。 The urls changed via push state lead to some directories deeper. 通过推送状态更改的网址会导致一些目录更深。

I also have other normal relative links in the website and unfortunately they don't update. 我在网站上也有其他正常的相对链接,很遗憾,它们没有更新。 So if I click an url after loading the content and changing it via push state, the link tries to load the file one directory deeper... 因此,如果我在加载内容并通过推送状态对其进行更改后单击一个url,则该链接将尝试将文件加载到更深的目录中。

I need to use relative urls, so do you have other ideas? 我需要使用相对网址,所以您还有其他想法吗?

Edit: 编辑:

for example i have this url: 例如我有这个网址:

http://www.example.com/site/profile http://www.example.com/site/profile

i change it to this one via push state for example: 我通过推送状态将其更改为此,例如:

http://www.example.com/site/profile/information http://www.example.com/site/profile/信息

And i have a link that leads relative to another file, for example: 而且我有一个相对于另一个文件的链接,例如:

<a href="../anotherSite">

The Problem is that the relative links are not updated, so after the url was changed, the link leads to: http://www.example.com/site/anotherSite and not http://www.example.com/anotherSite like it should... 问题是相对链接没有更新,因此在更改了URL之后,链接指向: http : //www.example.com/site/anotherSite,而不是http://www.example.com/anotherSite这应该...

Okay, finally after some hours of search I found a solution and after asking that question, too. 好吧,终于经过几个小时的搜索,我找到了解决方案,并问了这个问题。

I set a base url, so I dont have to update the urls. 我设置了基本URL,因此不必更新URL。

(base html tag) (基本html标记)

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

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