All Projects → ui-router → sticky-states

ui-router / sticky-states

Licence: MIT License
Sticky states for UI-Router 1.0

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sticky-states

Ui Router
The de-facto solution to flexible routing with nested views in AngularJS
Stars: ✭ 13,738 (+32609.52%)
Mutual labels:  ui-router, state-tree
ng2-multi-step-wizard-ui-router1
Series 3: Tutorials on creating an Angular 2 Multi-Step Wizard using UI-Router 1.0 and TypeScript 2.0.10
Stars: ✭ 33 (-21.43%)
Mutual labels:  ui-router
redux-leaves
Write once. Reduce anywhere.
Stars: ✭ 52 (+23.81%)
Mutual labels:  state-tree
polymer-ui-router
UI-router wrapper for Web Components
Stars: ✭ 24 (-42.86%)
Mutual labels:  ui-router
components
Example Components (Built with Tonic)
Stars: ✭ 62 (+47.62%)
Mutual labels:  ui-router
angular-page-loader
quick app integration for your favourite loaders
Stars: ✭ 13 (-69.05%)
Mutual labels:  ui-router
angular-middleware
Laravel-like middleware for Angular ui.router and ngRoute
Stars: ✭ 33 (-21.43%)
Mutual labels:  ui-router
angular-webpack-material-lazyload-typescript-starter-template
Angular starter template using typescript, angular-material, ui-router, oclazyload with webpack support.
Stars: ✭ 55 (+30.95%)
Mutual labels:  ui-router
mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (+78.57%)
Mutual labels:  state-tree
Mobx State Tree
Full-featured reactive state management without the boilerplate
Stars: ✭ 6,317 (+14940.48%)
Mutual labels:  state-tree
Immer
Create the next immutable state by mutating the current one
Stars: ✭ 21,756 (+51700%)
Mutual labels:  state-tree

Sticky States

Greenkeeper badge

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.

Using

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

ng1

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

import {StickyStatesPlugin} from "@uirouter/sticky-states";

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

ng2

In Angular 2, register a plugin in your UIRouterConfig class

import {StickyStatesPlugin} from "@uirouter/sticky-states";

export class MyConfig {
  configure(uiRouter: UIRouter) {
    uiRouter.plugin(StickyStatesPlugin);
  }
}

react

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

import {StickyStatesPlugin} from "@uirouter/sticky-states";

let router = new UIRouterReact();
router.plugin(StickyStatesPlugin);

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 target a named ui-view. The named ui-view must not be shared with other states.

Create and target a named ui-view.

  <ui-view name="admin"></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.

Example

These minimal examples show how to get started with sticky states in:

More

This project was ported from the UI-Router Extras project for legacy UI-Router. For more information, see the ui-router extras documentation: http://christopherthielen.github.io/ui-router-extras/#/sticky

TODO: Rewrite docs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].