- Notifications
You must be signed in to change notification settings - Fork49
UI-Router for Angular - Sample Application (angular-cli)
ui-router/sample-app-angular
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This project was generated withangular-cli version 1.0.0-beta.30.
Live demo:http://ui-router.github.io/sample-app-angular/#/mymessages/inbox/5648b50cc586cac4aed6836f
Edit this project in your browser:https://stackblitz.com/github/ui-router/sample-app-angular
This sample app is intended to demonstrate a non-trivial ui-router application.
- Multiple sub-modules
- Managed state lifecycle
- Application data lifecycle
- Authentication (simulated)
- Authenticated and unauthenticated states
- REST data retrieval (simulated)
- Lazy loaded Angular modules (contacts/mymessages/prefs submodules)
We're using theState and Transition Visualizer to visually representthe current state tree, as well as the transitions between states.Explore how transitions work by hovering over them, and clicking to expand details (params and resolves).
Note how states areentered when they were previously not active,exited and re-entered when parameters change,and how parent states whose parameters did not change areretained.Each of these (exited, entered, retained) correspond to a Transition Hook.
There are many ways to structure a ui-router app.We aren't super opinionated on application structure.Use what works for you.We organized ours in the following way:
- Feature modules
- Each feature gets its own directory and Angular Module (
@NgModule) - Features contain states and components
- Specific types of helper code (directives, services, etc)used only within a feature may live in a subdirectorynamed after its type
- Each feature gets its own directory and Angular Module (
- Leveraging ES6 modules
- States for a module are defined in separate file
- Each component is defined in its own file
- Components are referenced in states where they are composed into the state definition
- States export themselves
- Each feature
@NgModuleimports and declares all the states for the feature
- Defining custom, app-specific global behaviors
- Add metadata to a state, or state tree (such as
authRequired) - Check for metadata in transition hooks
- Example:
routerhooks/authRequired.js- If a transition to a state with a truthy
data.authRequired: trueproperty is started and the user is not currently authenticated
- If a transition to a state with a truthy
- Add metadata to a state, or state tree (such as
- Defining a default substate for a top-level state
- Example: declaring
redirectTo: 'welcome'inapp.states.ts
- Example: declaring
- Defining a default parameter for a state
- Example:
folderIdparameter defaults to 'inbox' inmymessages.states.ts(folder state)
- Example:
- Application data lifecycle
- Data loading is managed by the state declaration, via the
resolve:block - Data is fetched before the state isentered
- Data is fetched according to state parameters
- The state isentered when the data is ready
- The resolved data is injected into the components
- The resolve data remains loaded until the state is exited
- Data loading is managed by the state declaration, via the
- Lazy Loaded states
- The main submodules (and all their states and components) are lazy loaded
- The future state includes a
loadChildrenproperty which is used to lazy load the module
About
UI-Router for Angular - Sample Application (angular-cli)
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors14
Uh oh!
There was an error while loading.Please reload this page.