Creating Hub

So, in this step, we have to create a router module that has a connection purpose.

import { ModuleWithProviders, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { connectFeatures, createRoot, NavigationModule } from 'routeshub';

import { routes } from './app.routes';
import { APP_NOTES_KEY, AppChildNotes, AppNotes } from './app.notes';
import { aboutConnector } from '../views/about/hub/about.hub';
import { AboutNotes } from '../views/about/hub/about.notes';
import { authConnector } from '../views/auth/hub/auth.hub';
import { AuthNotes } from '../views/auth/hub/auth.notes';
import { locationConnector } from '../views/location/hub/location.hub';
import { LocationNotes } from '../views/location/hub/location.notes';

createRoot<AppNotes, AppChildNotes>(routes, 
  {
      /**
      * key prop is familiar for all of us
      * it provides a possibility to identify the unit
      */
      key: APP_NOTES_KEY,
      /**
      * you may be confused about routeName property of options
      * by default route path '' transforms into property 'root'
      * and '**' transforms into property 'wildcard'
      */
      routeName: { wildcard: 'notFound' },
      /**
      * nearby prop are modules which were imported into the module
      * but they have their own routes files without direct routes relations
      * with module in which they were imported
      * paths in module they were imported
      */
      nearby: {
          location: locationConnector
      }
  }
);

/**
* connects feature modules with direct path relations
* could be invoked at any time during runtime
*/
connectFeatures<AppNotes, AppChildNotes>(APP_NOTES_KEY, {
  about: aboutConnector,
  auth: authConnector
});

/**
 * Describes the project's hubs (optional)
 */
export interface Hub {
  app: AppNotes & AppChildNotes;
  about: AboutNotes;
  auth: AuthNotes;
  location: LocationNotes;
}

export const routing: ModuleWithProviders = RouterModule.forRoot(routes);

@NgModule({
  imports: [routing],
  exports: [RouterModule, NavigationModule]
})
export class AppHub {
}

Last updated