Coder Social home page Coder Social logo

uirouterbot / sample-app-angular-hybrid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ui-router/sample-app-angular-hybrid

0.0 0.0 0.0 13.36 MB

UI-Router Hybrid Sample App: Route to Angular 1 and Angular 2 components

Home Page: https://ui-router.github.io/sample-app-angular-hybrid

TypeScript 79.98% JavaScript 11.97% Shell 0.67% HTML 1.18% CSS 6.20%

sample-app-angular-hybrid's Introduction

UI-Router 1.0 Hybrid Angular/AngularJS Sample Application

https://ui-router.github.io/sample-app-angular-hybrid/#!/mymessages/inbox/5648b50d5d8be25776881a3f

Travis badge

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 sub module (Contacts)

Running

npm install npm start

Angular-CLI

The sample app has also been migrated to use the Angular CLI instead of custom webpack config. This can be seen in the angular-cli branch. Because it uses the CLI, it can also be live edited using stackblitz:

https://stackblitz.com/github/ui-router/sample-app-angular-hybrid/tree/angular-cli


Visualizer

We're using the State and Transition Visualizer to visually represent the 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 are entered when they were previously not active, exited and re-entered when parameters change, and how parent states whose parameters did not change are retained. Each of these (exited, entered, retained) correspond to a Transition Hook.

Structure

The application is written in Typescript and utilizes ES6 modules. We are loading and bundling modules using webpack.

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:

  • Sub-module (feature) organization
    • Each feature gets its own directory.
    • Features contain states and components
    • Specific types of helper code (directives, services, etc) used only within a feature may live in a subdirectory named after its type (/mymessages/directives)
  • Leveraging ES6 modules
    • Each state is defined in its own file
    • Each component (controller + template) is defined in its own file
    • Components exported themselves
    • Components are then imported into a states where they are composed into the state definition.
    • States export themselves
    • The feature.module.js imports all states for the feature and registers then with the $stateProvider
  • A single angular module is defined for the entire application
    • Created, then exported from bootstrap/ngmodule.js
    • The ng module is imported into some other module whenever services, config blocks, directives, etc need to be registered with angular.

UI-Router Patterns

  • Defining custom, app-specific global behaviors
    • Add metadata to a state, or state tree
    • Check for metadata in transition hooks
    • Example: routerhooks/redirectTo.js
      • If a transition directly to a state with a redirectTo property is started, the transition will be redirected to the state which the property names.
    • Example: routerhooks/authRequired.js
      • If a transition to a state with a truthy data.authRequired: true property is started and the user is not currently authenticated
  • Defining a default substate for a top-level state
    • Example: declaring redirectTo: 'mymessages.folder' in mymessages/mymessages.states.js (mymessages state)
  • Defining a default parameter for a state
    • Example: folderId parameter defaults to 'inbox' in mymessages/mymessages.states.js (folder state)
  • Application data lifecycle
    • Data loading is managed by the state declaration, via the resolve: block
    • Data is fetched before the state is entered
    • Data is fetched according to state parameters
    • The state is entered when the data is ready
    • The resolved data is injected into the components
    • The resolve data remains loaded until the state is exited
  • Lazy Loading
    • The contacts module is an Angular NgModule. It is defined as a "future state", and lazy loaded just before any contacts state is activated.

sample-app-angular-hybrid's People

Contributors

alexswensen avatar christopherthielen avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar dependencies-bot avatar elboman avatar greenkeeper[bot] avatar greenkeeperio-bot avatar vucalur avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.