After working for some time with the ui-router, I think it's not entirely suitable for our purposes because it uses a tree-like structure to describe routes with a single root state.
Say we have three panels which can be either open or closed: mainPanel
, sidePanel
, and filterPanel
. And we create the following routes (app
is an abstract root state):
"app.main"
: mainPanel
is open
"app.main.side"
: mainPanel
and its sidePanel
is open
"app.main.side.filter"
: all three panels are open
"app.main.filter"
: mainPanel
and filterPanel
"app.filter"
: filterPanel
is open
Problems start when you want to go from "app.main.filter"
to "app.filter"
by closing the mainPanel
but keeping the filterPanel
open. When switching between states, ui-router clears views populated by the current state leaving views populated by the parent states intact. So, switching to "app.filter"
will first remove filterPanel
from the dom and then re-insert it back.
View's HTML structure is not cached and will be reinitialized upon insertion which may involve a lot of calculations (removing and re-inserting a large datatable for example). Even worse, when the view is cleared, its leave
animation is triggered; on re-insertion, its enter
animation. We want the filterPanel
to stay put, not animate in and out when closing the mainPanel
.
Four possible ways around it:
- Drop animations for
enter/leave
transitions. We might still get flickering when components removed/re-inserted into the dom.
- Create a separate route for all possible combinations of components:
"app.main.filter.nomain"
for closing the mainPanel
when the filterPanel
stays open for example. I fear this can get ridiculous in a jiffy.
- Write a simple, custom state manager which let us control component's state independently of each other.
- Wait until the new angular router comes out with Angular 1.5 as it seems to solve this problem.