Practices - Do you use client-side routing?

Last updated by SSW.Rules.SharePointExtractor almost 4 years ago.See history

Single page applications (SPAs) are getting more and more popular, and for good reason – a better and faster user experience, reduced server load and encourages good API separation.

But have you ever visited a website, thought “I’ll refresh that” and then got taken back to the home screen? Or tried to copy or bookmark the URL, only to find it’s just “/Home”? This happens when client-side routing hasn’t been implemented properly and is a big hit to a site’s usability.

This is easily fixed with Angular ’s routing capabilities, and implementing it in your SPA will confer several advantages:

  • URLs can be copy-pasted and shared
  • Page refreshes work as expected
  • Less prone to errors
  • Better separation of concerns (navigation vs page state)

client side bad
Figure: Bad example - The blog post component is choosing components based on the state of the component

A better way is to set up routes, and use a router (the first-party component router is great for this) to manage your components:

client side good
Good: Setting up declarative routes and outlets gives a good user experience, persistent URLs, and fewer moving parts

Steve Leigh
Duncan Hunter
We open source.Loving SSW Rules? Star us on GitHub. Star
Stand by... we're migrating this site to TinaCMS