Question

[Updated to focus question]. AngularDart nicely supports modular app design in many respects. Is this also the case for route design? I.e.,

Question: Can an app have more than one RouteInitializer? E.g., would the following be possible:

class MyAppModule extends Module {
  MyAppModule() { ...
    type(RouteInitializer, 
       // Currently implementedBy takes only one RouteInitializer? 
       // Here we propose, e.g., to allow a list.
       implementedBy: 
         [MyAppRouteInitializerForFeatureSetA,
         MyAppRouteInitializerForFeatureSetB,
         MyAppRouteInitializerForFeatureSetC,
         ]);
    ...
  }
}

Use case: I am considering asking some of my students to work on the same AngularDart project, but on (mostly) mutually exclusive feature sets. Ideally I would like for them to work independently (once a "top-level" route URL prefixes are agreed upon). In such a case they would end up having their own RouteInitializers. It would be nice to be able to just "drop" in their project subfolders, come integration time, rather than copy-pasting route initialization into a single class file.


[Original version of question] (Given that the interface name is RouteInitializer, rather than possibly RouterInitializer, gives the impression more than one can be defined.)

  1. Is this also the case for route design? I.e.,
  2. How many Router instances can be associated to an Angular Dart app? (I suppose only one.)
  3. Can an app have more than one RouteInitializer? (Given that the interface name is RouteInitializer, rather than possibly RouterInitializer, gives the impression more than one can be defined.
  4. If more than one RouteInitializer is permitted, then what is the scope of the addRoute name parameter?

Edit: actually the last question has merit of its own in the context of hierarchical routes, so I factored it out to here: angulardart-namespace-of-route-names-hierarchical-too.

Was it helpful?

Solution

Having multiple RouteInitializers is complicated, as you pointed out.

Technically you don't needs help form angular do achieve this.

my_routes.dart

import 'foo.dart' as foo;
import 'bar.dart' as bar;

myRouteInitializer(router, views) {
  views.configure({
    'foo': foo.configureFooRoutes(),
    'bar': bar.configureBarRoutes()
  });
}

foo.dart

library foo;

import '';

configureFooRoutes(views) => ngRoute(
    path: '/foo',
    mount: ...);

bar.dart

library bar;

import '';

configureBarRoutes(views) => ngRoute(
    path: '/bar',
    mount: ...);

This way your students can work independently.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top