Matteo
Matteo

Reputation: 1271

ionic-v4 Navigate application with url

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]}]

Upvotes: 0

Views: 31

Answers (1)

jamespsterling
jamespsterling

Reputation: 43

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.

Upvotes: 1

Related Questions