Getting trunk routing to work with pushstate and node.js / express as a server

I am trying to create a one-page application with backbone.js on the front side and node.js / express as a server, I want to have a basic HTML file for the root, and then when the user goes to any path, such as

mydomain.com/foo/bar

I want to be able to handle this path on the client side using javascript instead of making a trip back to the server. I read about backbone routing and click state of HTML5. In this article, he describes the state of depression, for example,

In fact, PushState is actually nothing more than a standard JavaScript API that allows us to manipulate the browser history by “pushing” the full URLs into the browser URL, without back-and-forth to the server and without responding to changes in the URL with Javascript - all without the use of URL hash fragments.

but when I use push state, it actually makes a server request and expects the server to deliver content to / foo / bar. I do not understand how I can avoid this.

Now suppose that even with the click of a button, your client will make a request to the server under mydomain.com/foo/bar when directly visiting this URL. In this case, since I serve the default HTML file, and this HTML file by default has script links in it:

<script type="text/javascript" src="/scripts/myscript.js" ></script>

HTML , /foo root, /foo, , , . ?

. , URL- . . , : : # URL

+4
1

, , , . mydomain.com/foo/bar, , (JavaScript) , , . :

  • GET http://mydomain.com/foo/bar
  • ( 302 ) http://mydomain.com/#!/foo/bar
  • SPA , #!/foo/bar, /foo/bar ( push). URL http://mydomain.com/foo/bar: URL, .

Grooveshark - , , 1., , . , , - .

+4

Source: https://habr.com/ru/post/1533793/


All Articles