This is just how URLs work.
https://
determines how to ask for the resourcewww.example.com
determines what server to ask for it from/some/path/?query=optional
determines what to ask the server for#fragment
is handled client-side and determines where the browser scrolls to on the page
There isn’t a sensible way to make the part of the URL that is sent to the server be treated as the part the browser uses to determine where to scroll to.
If you want to head down routes that are not sensible…
- Make the server-side code deliver the same HTML document for every
/path
you want to represent a part of the same page - Mark the primary URL as canonical
- Add some client-side JS that:
- waits for the DOMContentLoaded event
- Reads the location to get the path
- Uses some internal logic to determine what element to scroll to
- Uses scrollTo to scroll to it/Element/scrollTo
- Add some more client-side JS that:
- Listens for click events on your internal links
- uses
pushState
andpreventDefault
to change the URL without leaving the current (identical) page - Reads the URL from the
href
of the clicked link - Does the same as steps 3.3 and 3.4
- Add some more client-side JS that
- listens for popstate events
- gets the URL the user is going back to
- Does the same as steps 3.3 and 3.4
… now that’s a lot of work to make URLs act in a non-standard way.
solved How do I change sections in HTML without getting ‘#’ in the Link? [closed]