Angular: Should Routing be done in its own module? -


from angular documentation, routing example has routing done inside same module 1 trying route (appmodule). such:

const approutes: routes = [   { path: 'crisis-center', component: crisislistcomponent },   { path: 'hero/:id',      component: herodetailcomponent },   {     path: 'heroes',     component: herolistcomponent,     data: { title: 'heroes list' }   },   { path: '',     redirectto: '/heroes',     pathmatch: 'full'   },   { path: '**', component: pagenotfoundcomponent } ];  @ngmodule({   imports: [     routermodule.forroot(       approutes,       { enabletracing: true } // <-- debugging purposes     )     // other imports here   ],   ... }) export class appmodule { } 

however, style guide angular mention use of routing module. therefor adding file approutingmodule , importing module in appmodule instead of having routing done in appmodule. , can gather various tutorials, guides , such, approutingmodule used.

yet, still confused structure supposed use. taught modules in software structure supposed have few dependencies possible can deployed and/or reused. isn't having separate module routing 100% dependent on other module against concept?

the routing approutingmodule won't work beside appmodule. why duplicate imports on every components used routing instead of creating routes in appmodule?

is there specific structure should using project (and why) or subject personal preference on how want structure project?

if u use module system, can make optimization step. in example:

  1. lazy router
  2. separate modules injection

you can check network. js update after loading new module.

this nice aot-compilation, can have fastest load without dependency.

if need shared modules, can create module , import , export modules how bootstrap, modal-window , other modules, when use in application.

pure component bad style code, because can't separated project project , have big monolyte project big dependency system linked .

you can saw modulated system on home project - https://github.com/adventure-rpg/adventure-client/tree/master/src


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -