Routing and Navigation in LWR on Node.js
What’s web routing about and why does it matter? Should I care about routing in my single page application (SPA)?
A route is a way to connect a URL for a web page (that is, a request path) with the resource to be served for that request.
A classic example of why web apps pay attention to routing is the browser “back” button. A web app could rely only on its own navigation (buttons, etc.) and not implement routing. However, if a user presses the browser’s “back” button, what happens then? The answer is: nothing good or reliable. The browser could drop the user back to the root of the app or outside of the app entirely.
So, should you care about routing in an SPA? The short answer is yes. You can read a great longer answer here.
Routing with LWR can be simple, but LWR also provides a great deal of routing sophistication. For example, LWR supports dynamic routes and complex content querying to handle scenarios such as pagination.
You can control routing with LWR in two ways:
- Server-side routing: best for simple routing needs
- Client-side routing: ideal for single-page applications (SPAs) and can be used in conjunction with server-side routing