Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

mdvorak/resource-router

Repository files navigation

resource-router

Build

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

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 build
    
  7. Publish the library
    npm publish dist/angular-resource-router
    
  8. Publish docs, if this is head release
    npm run ghpages
    
    Note: For this command to succeed, you must have ssh agent running at the background.
  9. 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