2

Can anybody help me please with resolve router question.

I have one main module "app.module" which consists of few submodules. App.module has app.routers file which describes lazy loading for its submodules.

The file app.routers looks like this:

..
{
    path: "sign-up", // to sing up new users
    loadChildren: "app/signup/sign-up.module"
},
{
    path: "home", // to see home page
    loadChildren: "app/home/home.module"
},
..
etc
..

I want to use resolve router to load some data from server and I want to do it in app.component when app.component is loading and before submodules load.

For example if www.myapp.com/home loads I want to get data from resolve router in app.component (in ngOnInit I guess) no in submodule.component.

Is it possible to describe path in app.routers which will load before another statments in app.routers?

Thanks in advance!

Updated

export const routes: Routes = [
    {
        path: "login", // to sign in or to see information about current logged user
        loadChildren: "app/login/login.module"
    },
    {
        path: "sign-up", // to sing up new users
        loadChildren: "app/signup/sign-up.module"
    },
    {
        path: "home", // to see home page
        loadChildren: "app/home/home.module"
    },
    {   // path by default, redirecting to home page
        path: "",
        redirectTo: "/home",
        pathMatch: "full"
    },
    {   // directory to see, edit, search countries
        resolve: {
            userData: UserResolve
        },
        path: "countries",
        loadChildren: "app/country/country.module"

    },
    { // any other page will redirect to Page404Component component
        path: "page404",
        loadChildren: "app/404/page404.module"
    },
    {   // path which doesn"t exist
        path: "**",
        redirectTo: "/page404",
        pathMatch: "full"
    }
];
Egor
  • 2,122
  • 2
  • 21
  • 23
  • First of all your loadChildren should reference the class name to load. Something like `loadChildren: "app/signup/sign-up.module#SignupModule"`. Second - your lazy-loaded modules will not load until you navigate to them. – rook Sep 13 '16 at 03:14
  • Do you have default path? show your routings as well. – micronyks Sep 13 '16 at 03:16
  • rook, for example I want to enter to my app throught the page www.example.com/home, so home component will be loading and can get resolve data but I want app component recieves resolve data when app loads – Egor Sep 13 '16 at 03:21
  • micronyks, I updated my question (added full routings) – Egor Sep 13 '16 at 03:23
  • Your default route is `/home` only. – micronyks Sep 13 '16 at 03:25

0 Answers0