url-routingreact-router

What is routing? Why is "routing" needed in single page web apps?


I understood that routing libraries for SPAs like https://github.com/ReactTraining/react-router help to parse the URL and put the app into a corresponding state of a state machine.

Is there more to routing than this?

Why is routing needed in the first place?

Why are URLs important? For example in a desktop app there are no URLs, so what's the big deal about them in a web app?


Solution

  • I also have this problem: "Why do we need routing?". You can write apps without routing at all. The code can get messy but still, it is not impossible.

    My biggest reason for having routing is because, if the user hits the Back button of the browser (Forward button as well, for that matter), they will not be navigating within the app. The user might expect to navigate within the app using the history of the different "pages" they loaded previously. Instead, they will be thrown out of the web app. Hitting the Refresh button would also throw them to the root of the app.

    From the user's point of view, it is a regular web app (they doesn't need to know how it is designed: SPA or otherwise) and it should work as any web app/website should work. Routing ensures this, doesn't it?