resource-router

Build Status

Angular routing engine that drive views by media types. It loads data itself, and by response Content-Type header it displays configured view. It is a replacement for original Angular Router (they cannot be used at the same time).

The aim of this library is to allow building of RESTful clients using Angular, following HATEOAS principle.

See CHANGELOG for release changes.

Installation

npm i angular-resource-router --save

Documentation

See API documentation for latest released version.

Configuration

Sample snippet how is the router configured. It is very similar to original router, but instead of registering paths, we are registering media types.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ResourceRouterModule } from 'angular-resource-router';
import { AppComponent } from './app.component';
import { SampleComponent } from './sample.component';
import { ErrorComponent } from './error.component';

@NgModule({
  declarations: [
    AppComponent,
    SampleComponent
  ],
  imports: [
    BrowserModule,
    ResourceRouterModule.configure({
      prefix: 'api/'
    }),
    ResourceRouterModule.forTypes([
      {
        type: 'application/x.sample',
        component: SampleComponent
      },
      {
        status: '*',
        type: '*',
        component: ErrorComponent
      }
    ])
  ],
  bootstrap: [
    AppComponent
  ]
})
export class ExampleModule {
}

How It Works

TODO

Development

Before development, run

npm run bootstrap

it will create necessary symlinks for build to pass.

Note: Under linux, you need to change global npm prefix to user accessible directory, see How to Prevent Permissions Errors.

Library

Build of the library is performed with

npm run build

Publishing

To publish new library version to npm repository:

  1. Verify/set library version in src/lib/package.json
  2. Make sure there are release notes in the CHANGELOG.
  3. Commit and push changes, if any
  4. Create a new release on GitHub, in the format v0.0.0 (or alternatively use git directly)
  5. Copy changelog markdown text to the release
  6. Build the library and make sure all tests passed
    npm run bootstrap
    npm run build
  7. Verify library is built correctly using
    npm run buildapp
  8. Publish the library
    npm publish dist/angular-resource-router
  9. Publish docs, if this is head release
    npm run ghpages
  10. Merge the branches if needed

Demo app

Local development server can be started with

npm start

TODO

Things that are yet to be implemented

  • Complete README
  • Complete example
  • Support for resolve and data route configs
  • Support for outlet layouts, outlet resolve
  • Outlet context data (name etc)
  • Navigation within outlet
  • Hide element if empty link
  • External navigation for unknown type
  • Build and publish docs
  • Typedoc

results matching ""

    No results matching ""