UI-Router Sticky States: Keep states and their components alive while a different state is activated
Last updated 3 years ago by dcarabott .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sn-ui-router-sticky-states 
SYNC missed versions from official npm registry.

Sticky States

Sticky States for UI-Router 1.0  Build Status

Overview and Use Case

Sticky States allows two or more trees of states to run concurrently along side each other.

The initial use case for this functionality is to implement "tabs" for application modules. Using Sticky States, a single app can implement one state tree for each tab, and have them operate at the same time, in parallel to each other. Each tab is implemented as its own UI-Router state tree. While one tab is active, the other tab is inactivated, but can be reactivated without losing any work in progress.

For the tabs use case, Sticky States work best along with Deep State Redirect

Sticky State Lifecycle

A Sticky State is the root of a UI-Router state tree which can continue running even after it is "exited". The sticky state (and its children) have a different lifecycle than normal states. The views of a Sticky State (and all activated substates) are retained until one of two things happen:

  • The parent of the sticky state is exited
  • The parent of the sticky state is directly activated

If a sibling of the sticky state (or a child of a sibling) is activated, the sticky state tree will "inactivate". A transition back to the inactivate state will reactivate it.


Sticky states works requires ui-router-core 2.0.0 or above. Run npm ls to check the version of ui-router-core included with the UI-Router distribution for your framework

1) Add Plugin


In Angular 1, register a plugin by injecting $uiRouterProvider in a config() block.

import {StickyStatesPlugin} from "ui-router-sticky-states";

angular.module('myapp', ['ui.router']).config(function($uiRouterProvider) {


In Angular 2, register a plugin in your UIRouterConfig class

import {StickyStatesPlugin} from "ui-router-sticky-states";

export class MyConfig {
  configure(uiRouter: UIRouter) {


In React, register a plugin after creating your UIRouterReact instance.

import {StickyStatesPlugin} from "ui-router-sticky-states";

let router = new UIRouterReact();

Or, if using component bootstrapping, add the plugin in your routerConfig function.

let routerConfig = (router) => router.plugin(StickyStatesPlugin);

return <UIRouterReact config={routerConfig}/>;

2) Mark a state as sticky

The sticky state's view must have its own unique ui-view (not shared by other states). Create and target a named ui-view.

let adminModule = {
  name: 'admin',
  sticky: true,
  views: {
    admin: { component: AdminComponent }

The AdminComponent should remain active in the ui-view named admin, even if a sibling state is activated.

3) Show/Hide the sticky component

When a sticky state is inactive, it's often desired to hide the contents from the UI. This can be achieved using StateService.includes.

In some cases, ui-sref-active may also be used to toggle a class on the named ui-view.


This project was ported from the UI-Router Extras project for legacy UI-Router. For more information, see the ui-router extras documentation:

TODO: Rewrite docs

Current Tags

  • 6.1.0                                ...           latest (3 years ago)

13 Versions

  • 6.1.0                                ...           3 years ago
  • 6.0.7                                ...           3 years ago
  • 6.0.6                                ...           3 years ago
  • 6.0.5                                ...           3 years ago
  • 6.0.4                                ...           3 years ago
  • 6.0.3                                ...           3 years ago
  • 6.0.2                                ...           3 years ago
  • 6.0.1                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 1.3.3                                ...           3 years ago
  • 1.3.2                                ...           3 years ago
  • 1.3.1                                ...           4 years ago
  • 1.3.0                                ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependents (0)

Copyright 2014 - 2017 © |