H
H
HoHsi2015-10-09 13:19:41
JavaScript
HoHsi, 2015-10-09 13:19:41

How is routing implemented on kinopoisk.ru and slack.com?

Good day!
How is routing implemented on sites like https://kinopoisk.ru and https://slack.com ? When you click on the link, the page is not reloaded, but simply updated via ajax.
Please note that everything works there not on hash routing (which would explain the lack of a reload), but on adult routing from the server side.
Or is it all done through the interception of clicks on links and the cancellation of the default action, using JS? And then just parsing links with ajax.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2015-10-09
@HoHsi

history.pushState
// EDIT for those in the tank (PSEUDOCODE)

$('a').on('click', function(event) {
  event.preventDefault();
  var url = $(this).attr('href');
  Router.change(url);
});

// Router.change
function change(url) {
  history.pushState(url);

  var view = this.getView(url);
  ViewManager.setView(view);

  var controller = this.getController(url);
  controller.dispatch();
}

P
Pavel Volintsev, 2015-10-09
@copist

To determine how the site loads information, use the debug panel in the browser, the "Network" tab ( illustration ) If a request of the XHR
type appeared when clicking on the link, then this is AJAX and there were no requests to the server, it means that the data has already been loaded into the browser and stored, for example, in RAM or in the browser 's LocalStorage ( illustration ) ) .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question