What is “front-end routing”? When is “front-end routing” suitable? What are the advantages and disadvantages of “front-end routing”?

  javascript

What is “front-end routing”? When is “front-end routing” suitable? What are the advantages and disadvantages of “front-end routing”?

To put it simply, we open a page that is a Single-page application:http://www.this-is-a-spa.com/
So it has only one page, but the author has made several URLs:

http://www.this-is-a-spa.com/a
 http://www.this-is-a-spa.com/b
 http://www.this-is-a-spa.com/c
 ...

These URLs will not be sent directly to the server, but will be digested and processed by the browser.

In doing so, we can:

  • When the browser reads one of the URL requests registered in the front-end route, for examplehttp://www.this-is-a-spa.com/aWhen accessing this URL, the pre-written event a can be triggered, so the event can be triggered directly. Can be used when writing<a href="/a">Event A</a>To trigger the event, but not necessarilyaddEventListener("click", ...)This way of writing, when the project logic is more complex, this way of organizing is much better than writing a lot of event registrations. (Of course SPA generally uses a framework, this way is only an option)

  • Users can collecthttp://www.this-is-a-spa.com/aGo to Favorites and trigger it directly after opening it./aThe event (and then automatically load data or something else), while SPA without front-end routing cannot achieve this effect, and its URL is unchanged from beginning to end.

So ~

  • What is a front-end route: Let’s just leave the route to the browser. Is there a textbook standard definition?

  • When is suitable for use: SPA can be used, in fact, it depends on product demand.

  • Advantages: as above;

  • Disadvantages: front end development Trouble? Need to learn another one? If it is also a shortcoming.