In the process of updating the application, I work with the latest candidate for the release of Angular 2. As part of this work, I try to use the NgModule specification and transfer all parts of my application to modules. For the most part, this went very well, with the exception of the routing problem.
"@angular/common": "2.0.0-rc.5", "@angular/compiler": "2.0.0-rc.5", "@angular/core": "2.0.0-rc.5", "@angular/forms": "0.3.0", "@angular/http": "2.0.0-rc.5", "@angular/platform-browser": "2.0.0-rc.5", "@angular/platform-browser-dynamic": "2.0.0-rc.5", "@angular/router": "3.0.0-rc.1",
My application is built as a composition of modules, while several modules are glued together as children of the parent module. For example, I have an administrator module, which consists of a notification module, a user module, and a telephone module (for example). The routes to these modules should look like ...
/admin/notifications/my-notifications /admin/users/new-user /admin/telephony/whatever
In an earlier version of the router, this was easy to do with "children"
export const AdminRoutes: RouterConfig = [ { path: "Admin", component: AdminComponent, Children: [ ...UserRoutes, ...TelephonyRoutes, ...NotificationRoutes ] } ]
In another file, as part of the submodules, I would define the routes of the individual modules, as well as ie
export const UserRoutes: RouterConfig = [ { path: "users", component: userComponent, children: [ {path: "new-user", component: newUserComponent} ] } ]
All this worked very well. In the process of upgrading to modules, I moved everything to my own routing files, and now these two are more like this.
const AdminRoutes: Routes = [ {path: "admin", component: AdminComponent} ] export const adminRouting = RouterModule.forChild(AdminRoutes)
and
const UserRoutes: Routes = [ path: "users", component: userComponent, children: [ {path: "new-user", component: newUserComponent} ] ] export const userRouting = RouterModule.forChild(UserRoutes)
With all this in place, I have a UserModule that imports userRouting, and then an AdminModule that imports adminRoutes and UserModule. I thought that since UserModule is a child of AdminModule, routing will work the way it is used to. Unfortunately, this is not so, I end up with a user route that is simply
/users/new-user
instead
/admin/users/new-user
In addition, because of this, the new user component does not load into the router socket of my admin component, which cancels the style and navigation of my application.
I canโt figure out for my whole life how to refer to the routes of my UserModule as children of my AdminModule. I tried to do it the old way and get errors about routes found in two modules. Obviously, as it is recently released, the documentation for some of these cases is slightly limited.
Any help anyone can provide would be greatly appreciated!