0

I am writing an ionic application from scratch. I built a login page and was able to successfully authenticate at the server. After authenticate i am routing to a page called "tabs" when i do this the url changes but the page still just shows the login screen. I am sure im missing something obvious but cant seem to figure it out.

this is the method

async login() {
         const loading = await this.loadingController.create();
         await loading.present();

        this.authService.login(this.credentials?.value).subscribe(
            async (res) => {
                await loading.dismiss(); 
        await this.router.navigate(['/tabs'],{ replaceUrl: true });
            },
            async (res) => {
                await loading.dismiss();
                const alert = await this.alertController.create({
                    header: 'Login failed',
                    message: res.error.error,
                    buttons: ['OK']
                });

                await alert.present();
            }
        );
    }

the url at the top will say http://localhost:8100/tabs

but the page being displayed is still the login page

  • Does your page tabs even exist? navigateByUrl is right in that case. Also make it asynchronous: Use await before executing this line – SickerDude43 Jul 28 '23 at 16:09
  • Also check this question: https://stackoverflow.com/questions/49130997/angular-async-router-guards – SickerDude43 Jul 28 '23 at 16:13
  • thank you for the response. the page definetly exists. i have updated the my original post with the full sample. i do have a guard on my route but it doesnt work when i remove it either – Joe Johnson Jul 28 '23 at 16:51
  • Such a problem may have much things causing it, probably would be better to upload a sample of ur project to git so people can look things up, but will mention below all things that could cause that problem.. You said tab page exist, does it have a route in app-routes? Are you sure the module of it is pointing on tabs module and not on login module? Does your console show error after navigating to tabs? is tabs page a tab layout or just a normal page? if its a tab layout, are you sure in the tab routing you have created a redirect to go to a specific tab if tab was not provided? – Mostafa Harb Jul 29 '23 at 09:56
  • And if it wasn't a tab layout, are you sure if in its tabs.module has a declaration in the ngmodule for TabsComponent? Your problem has really many possible things that could cause it so best thing is to post your project as it is still in the beginning and no real sensitive information in it so can be posted in git.. – Mostafa Harb Jul 29 '23 at 09:59
  • i ended up starting a brand new project since i hadn't done much in the one i was having a problem. everything works fine now. i have no idea what was causing that but its not a problem in the new project. thank you all for your responses – Joe Johnson Jul 29 '23 at 13:12
  • either way, try to use Ionic's own NavController instead of router, should not really be different but it's less prone to bugs, especially when working with ion-tabs. – AmirAli Saghaei Jul 30 '23 at 12:10

0 Answers0