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)?
The short answer is yes. 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. Routes are integral to letting users:
- Share and bookmark links to parts of your site.
- Use the browser's "back," "forward," and "refresh" buttons.
- Open pages in new windows or tabs.
Routing can be simple, but LWR also supports sophisticated routing configurations. For example, LWR supports dynamic routes and complex content querying to handle scenarios such as pagination.
For your LWR on Node.js site, you can control routing in two ways:
If your app uses server-side routing to manage page navigation, the user's entire webpage is reloaded before they can see the new page. In theory, the more complex your webpages are, the longer it takes for those pages to load from scratch. As a result, server-side routing is appropriate for simple routing needs.
Check out Server-Side Routing to learn more.
If your app uses client-side-routing, the browser changes the current URL and updates the UI of the current webpage as needed. Instead of reloading the entire page from scratch (like server-side routing), the browser may only reload certain elements on the page.
Client-side routing enables single-page applications (SPAs), and you can use it in conjunction with server-side routing. To learn more, see Client-Side Routing.