Routing after lazy loading is loading wrong component in Angular6





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I had implemented lazy loading on already developed application but after implementing, it is loading Any other component other than Home page and this is happening with the Home page only. My root level routing is like this:



{path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: '', loadChildren: './views/home/home.module#HomeModule'},
{ path: 'resetpass', loadChildren: './views/resetpass/resetpass.module#ResetpassModule'},
{ path: 'forgotpass', loadChildren: './views/forgotpass/forgot.module#ForgotpassModule'},
{ path: 'signup', loadChildren: './views/signup/signup.module#SignupModule'},
{ path: 'login', loadChildren: './views/login/login.module#LoginModule' },
{ path: 'otp', loadChildren: './views/otp/otp.module#OtpModule'},
{ path: 'school', loadChildren: './views/school/school-home/school-home.module#SchoolhomeModule'},
{ path: 'school/addstudents', loadChildren: './views/school/add-students/add-students.module#AddstudentsModule'},
{ path: 'school/managestudents', loadChildren: './views/school/manage-students/manage-students.module#ManagestudentsModule'},
{ path: 'school/ViewLogsDetails', loadChildren: './views/school/View-Log-Details/logdetails.module#LogdetailsModule'},
{ path: 'school/accountinfo', loadChildren: './views/school/accountinfo/accountinfo.module#AccountinfoModule'},
{ path: 'school/subscribe', loadChildren: './views/school/cals-subscribe/cal-subscribe.module#CalsubscribeModule'},
{ path: 'school/addstaff', loadChildren: './views/school/add-staff/add-staff.module#AddstaffModule'},
{ path: 'school/trans-track/:id', loadChildren: './views/school/trans-track/trans-track.module#TranstrackModule'},
{ path: '**', loadChildren: './views/home/home.module#HomeModule' }


On the home page, this loads AddstudentsComponent, even it should work just after login, here is the routing module for AddStudent:



import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AddStudentsComponent } from './add-students.component';

const routes: Routes = [
{ path: '', component: AddStudentsComponent}
];

@NgModule({
exports: [RouterModule],
imports: [RouterModule.forChild(routes)]
})
export class AddstudentsRoutingModule { }


As soon as I change path from '' to something like 'school/addstudent', it start loading AddStaff component.



Entire application was working fine until I put Module in each component level. Don't know how to copeup.










share|improve this question























  • there is no route for home

    – CruelEngine
    Nov 24 '18 at 6:26











  • I had mentioned few of Lazy Loading module in root level modules, this is why application was inconsistent.

    – Jay
    Nov 24 '18 at 8:21


















0















I had implemented lazy loading on already developed application but after implementing, it is loading Any other component other than Home page and this is happening with the Home page only. My root level routing is like this:



{path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: '', loadChildren: './views/home/home.module#HomeModule'},
{ path: 'resetpass', loadChildren: './views/resetpass/resetpass.module#ResetpassModule'},
{ path: 'forgotpass', loadChildren: './views/forgotpass/forgot.module#ForgotpassModule'},
{ path: 'signup', loadChildren: './views/signup/signup.module#SignupModule'},
{ path: 'login', loadChildren: './views/login/login.module#LoginModule' },
{ path: 'otp', loadChildren: './views/otp/otp.module#OtpModule'},
{ path: 'school', loadChildren: './views/school/school-home/school-home.module#SchoolhomeModule'},
{ path: 'school/addstudents', loadChildren: './views/school/add-students/add-students.module#AddstudentsModule'},
{ path: 'school/managestudents', loadChildren: './views/school/manage-students/manage-students.module#ManagestudentsModule'},
{ path: 'school/ViewLogsDetails', loadChildren: './views/school/View-Log-Details/logdetails.module#LogdetailsModule'},
{ path: 'school/accountinfo', loadChildren: './views/school/accountinfo/accountinfo.module#AccountinfoModule'},
{ path: 'school/subscribe', loadChildren: './views/school/cals-subscribe/cal-subscribe.module#CalsubscribeModule'},
{ path: 'school/addstaff', loadChildren: './views/school/add-staff/add-staff.module#AddstaffModule'},
{ path: 'school/trans-track/:id', loadChildren: './views/school/trans-track/trans-track.module#TranstrackModule'},
{ path: '**', loadChildren: './views/home/home.module#HomeModule' }


On the home page, this loads AddstudentsComponent, even it should work just after login, here is the routing module for AddStudent:



import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AddStudentsComponent } from './add-students.component';

const routes: Routes = [
{ path: '', component: AddStudentsComponent}
];

@NgModule({
exports: [RouterModule],
imports: [RouterModule.forChild(routes)]
})
export class AddstudentsRoutingModule { }


As soon as I change path from '' to something like 'school/addstudent', it start loading AddStaff component.



Entire application was working fine until I put Module in each component level. Don't know how to copeup.










share|improve this question























  • there is no route for home

    – CruelEngine
    Nov 24 '18 at 6:26











  • I had mentioned few of Lazy Loading module in root level modules, this is why application was inconsistent.

    – Jay
    Nov 24 '18 at 8:21














0












0








0








I had implemented lazy loading on already developed application but after implementing, it is loading Any other component other than Home page and this is happening with the Home page only. My root level routing is like this:



{path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: '', loadChildren: './views/home/home.module#HomeModule'},
{ path: 'resetpass', loadChildren: './views/resetpass/resetpass.module#ResetpassModule'},
{ path: 'forgotpass', loadChildren: './views/forgotpass/forgot.module#ForgotpassModule'},
{ path: 'signup', loadChildren: './views/signup/signup.module#SignupModule'},
{ path: 'login', loadChildren: './views/login/login.module#LoginModule' },
{ path: 'otp', loadChildren: './views/otp/otp.module#OtpModule'},
{ path: 'school', loadChildren: './views/school/school-home/school-home.module#SchoolhomeModule'},
{ path: 'school/addstudents', loadChildren: './views/school/add-students/add-students.module#AddstudentsModule'},
{ path: 'school/managestudents', loadChildren: './views/school/manage-students/manage-students.module#ManagestudentsModule'},
{ path: 'school/ViewLogsDetails', loadChildren: './views/school/View-Log-Details/logdetails.module#LogdetailsModule'},
{ path: 'school/accountinfo', loadChildren: './views/school/accountinfo/accountinfo.module#AccountinfoModule'},
{ path: 'school/subscribe', loadChildren: './views/school/cals-subscribe/cal-subscribe.module#CalsubscribeModule'},
{ path: 'school/addstaff', loadChildren: './views/school/add-staff/add-staff.module#AddstaffModule'},
{ path: 'school/trans-track/:id', loadChildren: './views/school/trans-track/trans-track.module#TranstrackModule'},
{ path: '**', loadChildren: './views/home/home.module#HomeModule' }


On the home page, this loads AddstudentsComponent, even it should work just after login, here is the routing module for AddStudent:



import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AddStudentsComponent } from './add-students.component';

const routes: Routes = [
{ path: '', component: AddStudentsComponent}
];

@NgModule({
exports: [RouterModule],
imports: [RouterModule.forChild(routes)]
})
export class AddstudentsRoutingModule { }


As soon as I change path from '' to something like 'school/addstudent', it start loading AddStaff component.



Entire application was working fine until I put Module in each component level. Don't know how to copeup.










share|improve this question














I had implemented lazy loading on already developed application but after implementing, it is loading Any other component other than Home page and this is happening with the Home page only. My root level routing is like this:



{path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: '', loadChildren: './views/home/home.module#HomeModule'},
{ path: 'resetpass', loadChildren: './views/resetpass/resetpass.module#ResetpassModule'},
{ path: 'forgotpass', loadChildren: './views/forgotpass/forgot.module#ForgotpassModule'},
{ path: 'signup', loadChildren: './views/signup/signup.module#SignupModule'},
{ path: 'login', loadChildren: './views/login/login.module#LoginModule' },
{ path: 'otp', loadChildren: './views/otp/otp.module#OtpModule'},
{ path: 'school', loadChildren: './views/school/school-home/school-home.module#SchoolhomeModule'},
{ path: 'school/addstudents', loadChildren: './views/school/add-students/add-students.module#AddstudentsModule'},
{ path: 'school/managestudents', loadChildren: './views/school/manage-students/manage-students.module#ManagestudentsModule'},
{ path: 'school/ViewLogsDetails', loadChildren: './views/school/View-Log-Details/logdetails.module#LogdetailsModule'},
{ path: 'school/accountinfo', loadChildren: './views/school/accountinfo/accountinfo.module#AccountinfoModule'},
{ path: 'school/subscribe', loadChildren: './views/school/cals-subscribe/cal-subscribe.module#CalsubscribeModule'},
{ path: 'school/addstaff', loadChildren: './views/school/add-staff/add-staff.module#AddstaffModule'},
{ path: 'school/trans-track/:id', loadChildren: './views/school/trans-track/trans-track.module#TranstrackModule'},
{ path: '**', loadChildren: './views/home/home.module#HomeModule' }


On the home page, this loads AddstudentsComponent, even it should work just after login, here is the routing module for AddStudent:



import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AddStudentsComponent } from './add-students.component';

const routes: Routes = [
{ path: '', component: AddStudentsComponent}
];

@NgModule({
exports: [RouterModule],
imports: [RouterModule.forChild(routes)]
})
export class AddstudentsRoutingModule { }


As soon as I change path from '' to something like 'school/addstudent', it start loading AddStaff component.



Entire application was working fine until I put Module in each component level. Don't know how to copeup.







angular angular6






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 2:57









JayJay

417




417













  • there is no route for home

    – CruelEngine
    Nov 24 '18 at 6:26











  • I had mentioned few of Lazy Loading module in root level modules, this is why application was inconsistent.

    – Jay
    Nov 24 '18 at 8:21



















  • there is no route for home

    – CruelEngine
    Nov 24 '18 at 6:26











  • I had mentioned few of Lazy Loading module in root level modules, this is why application was inconsistent.

    – Jay
    Nov 24 '18 at 8:21

















there is no route for home

– CruelEngine
Nov 24 '18 at 6:26





there is no route for home

– CruelEngine
Nov 24 '18 at 6:26













I had mentioned few of Lazy Loading module in root level modules, this is why application was inconsistent.

– Jay
Nov 24 '18 at 8:21





I had mentioned few of Lazy Loading module in root level modules, this is why application was inconsistent.

– Jay
Nov 24 '18 at 8:21












1 Answer
1






active

oldest

votes


















0














I have included Lazy Loading Module in app.module.ts like this:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


But I have not done the same with other component level modules. So the application was behaving incosistantly.



What I did now is to remove Component Level Modules from app.module.ts, like this line was removed:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


And, it becam consistent.






share|improve this answer
























  • You might have imported the module in your the imports array of your @NgModule object. the import you are mentioning has nothing to do with the inconsistency. When you import the module in another module, it is not lazy-loaded anymore.

    – Sachin Gupta
    Nov 24 '18 at 10:35












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454796%2frouting-after-lazy-loading-is-loading-wrong-component-in-angular6%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I have included Lazy Loading Module in app.module.ts like this:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


But I have not done the same with other component level modules. So the application was behaving incosistantly.



What I did now is to remove Component Level Modules from app.module.ts, like this line was removed:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


And, it becam consistent.






share|improve this answer
























  • You might have imported the module in your the imports array of your @NgModule object. the import you are mentioning has nothing to do with the inconsistency. When you import the module in another module, it is not lazy-loaded anymore.

    – Sachin Gupta
    Nov 24 '18 at 10:35
















0














I have included Lazy Loading Module in app.module.ts like this:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


But I have not done the same with other component level modules. So the application was behaving incosistantly.



What I did now is to remove Component Level Modules from app.module.ts, like this line was removed:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


And, it becam consistent.






share|improve this answer
























  • You might have imported the module in your the imports array of your @NgModule object. the import you are mentioning has nothing to do with the inconsistency. When you import the module in another module, it is not lazy-loaded anymore.

    – Sachin Gupta
    Nov 24 '18 at 10:35














0












0








0







I have included Lazy Loading Module in app.module.ts like this:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


But I have not done the same with other component level modules. So the application was behaving incosistantly.



What I did now is to remove Component Level Modules from app.module.ts, like this line was removed:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


And, it becam consistent.






share|improve this answer













I have included Lazy Loading Module in app.module.ts like this:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


But I have not done the same with other component level modules. So the application was behaving incosistantly.



What I did now is to remove Component Level Modules from app.module.ts, like this line was removed:



import { AddstaffModule } from './views/school/add-staff/add-staff.module';


And, it becam consistent.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 8:25









JayJay

417




417













  • You might have imported the module in your the imports array of your @NgModule object. the import you are mentioning has nothing to do with the inconsistency. When you import the module in another module, it is not lazy-loaded anymore.

    – Sachin Gupta
    Nov 24 '18 at 10:35



















  • You might have imported the module in your the imports array of your @NgModule object. the import you are mentioning has nothing to do with the inconsistency. When you import the module in another module, it is not lazy-loaded anymore.

    – Sachin Gupta
    Nov 24 '18 at 10:35

















You might have imported the module in your the imports array of your @NgModule object. the import you are mentioning has nothing to do with the inconsistency. When you import the module in another module, it is not lazy-loaded anymore.

– Sachin Gupta
Nov 24 '18 at 10:35





You might have imported the module in your the imports array of your @NgModule object. the import you are mentioning has nothing to do with the inconsistency. When you import the module in another module, it is not lazy-loaded anymore.

– Sachin Gupta
Nov 24 '18 at 10:35




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454796%2frouting-after-lazy-loading-is-loading-wrong-component-in-angular6%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()