Vin So
2 min readNov 9, 2016

--

Router instantiates a new component every time navigating to a different component type. This has serious repercussions. Also, this is very different paradigm not only from previous versions of the router, but any routing framework.

Here is an example: A user may be in the middle of filling a long form on a tab1, he needs to lookup or verify some other details in tab2, when he comes back to tab1, everything is wiped out (as the component is re-instantiated). This implies that every time a user makes a change on a part of the UI, the state of the UI should be preserved (in anticipation of his unexpected navigation to another component, which co-exists on the same UI.

On a complex UI, say with graphics and multiple open tree controls (reflecting a user who is in middle of doing some work), one would have to not only preserve content, but also unnecessarily preserve state of every widgets and/or position of graphics on the component. If the router had an option of reusing the components on the tree, (when navigating to a component of a different type from current component), one doesn’t have to preserve the UI state at all. It comes for free, because the component is still there.

This idea of destroying the component every time (someone navigates to a different type of component) doesn’t sound right from a performance point of view as well. The model from heavy back-end call, would have to be cached or call repeated. Every time a user navigates, there is something destroyed and something created, for no reason, what-so-ever.

What are your experiences with these simple use-cases and this new routing model? Do you think Router serves this fundamentally common use case described above.

This router model also makes the developer do a lot extra work (to preserve and recreate the work in progress — which we have never even cared about in our career as UI developers, as it is just work in progress). How do we overcome these challenges?

UI-router another third party routing library (has been around since angular1 days) doesn’t mandate/ force the developer these hardships by recreating components on navigation. It feels like a more sane approach. What do you think?

--

--