S
S
Saboteur2021-04-08 15:29:05
Iron
Saboteur, 2021-04-08 15:29:05

How to update the url in the address bar or what to do?

Stupid question.
I decided to make a simple site, without links. When you click on the menu, the main block is simply updated, or the finished text is simply entered, or it is loaded via ajax.

The problem is that the link in the browser naturally does not change and copy it and throw it to someone - he will naturally receive a link to the beginning, and not to the "submenu".

Which approach is correct in general - I'm not sure that I can replace the link in the address bar from JS.
But how then to get out of the situation? Creating a "copy link" button on each page seems to me not the most correct option.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2021-04-08
@saboteur_kiev

If you want to do something similar to SPA (Single Page Application), then first you need to teach the server to always return index.html. The next step is the History API, this will come in handy for URL spoofing and generating your links. And in order to download the necessary content, it will be necessary to parse location.pathnameand display the necessary information (as if you clicked on a menu item).
The second option is simpler - use it location.hashto store a unique URL, you will upload the same as in the first option.

N
NedoKoder, 2021-04-08
@NedoKoder

https://github.com/kapitonoval/Js-Url-Edit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question