0

I have a login page and three pages, I would like to navigate through the url. That is, I would like to write on the address bar of the browser:

localhost:8100/mySite/page1 

and go to page 1

localhost:8100/mySite/page3 

and go to page 3

My problem is that every time I write an address in the address bar Ionic-v4 reloads the entire application and takes me back to the login page.

const routes: Routes = [ {path: '', redirectTo: 'login', pathMatch: 'full'}, {path: 'p1', loadChildren: './pages/p1/p1.module#P1Module', canActivate: [AuthGuard]}, {path: 'p2', loadChildren: './pages/p2/p2.module#P2Module', canActivate: [AuthGuard]}, {path: 'p3', loadChildren: './pages/p3/p3.module#P3Module', canActivate: [AuthGuard]}]

1 Answer 1

1

It appears your routes for /mySite/pageX do not match your route definitions, hence it's defaulting to the login path.

Try defining your routes like,

const routes: Routes = [ {path: '', redirectTo: 'login', pathMatch: 'full'}, {path: 'mySite/page1', loadChildren: './pages/p1/p1.module#P1Module', canActivate: [AuthGuard]}, {path: 'mySite/page2', loadChildren: './pages/p2/p2.module#P2Module', canActivate: [AuthGuard]}, {path: 'mySite/page3', loadChildren: './pages/p3/p3.module#P3Module', canActivate: [AuthGuard]} ] 

Additionally, your AuthGuard could be sending you to the login route if not properly fulfilled.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.