Home > Net >  Angular Routing- I have no errors but I cannot do the routing. I see white screen and no errors
Angular Routing- I have no errors but I cannot do the routing. I see white screen and no errors

Time:12-25

I am trying to learn angular routing. I can see white screen and no errors.I want to route from app to homepage.

Here is the code.

For App:

app-routing.module.ts

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [


  {
    path:'',
    loadChildren: () => import('./pages/home/home.module').then(m => m.HomeModule)
  }

];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule {}

app.component.html

<ion-app>
  <ion-router-outlet></ion-router-outlet>
</ion-app>

app.component.scss

//Empty

app.component.ts

import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {


  constructor() {

    
  }
}

For Homepage:

home-routing.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomePage } from './home.page';



const routes: Routes = [
  {
      path:' ',
      component:HomePage

  }
];

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

home.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HomePageRoutingModule } from './home-routing.module';
import { HomePage } from './home.page';
import { IonicModule } from '@ionic/angular';
import { FormsModule } from '@angular/forms';



@NgModule({

  imports: [
    CommonModule,

    IonicModule,
    HomePageRoutingModule,
    FormsModule
  ],
    declarations: [HomePage],
})
export class HomeModule { }

home.page.html

<p> Home Page Works!<p>

home.page.scss

//Empty

home.page.ts

import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {


  constructor() {

    
  }
}

After I run it, I don't see any errors in the console. The browser is a white blank screen. It is supposed to show "Homepage works".

I am using Ionic 6 and Angular version. I am also using capacitor. Then , can you tell me why is it not running? I am scratching my head for few hours. Thanks

CodePudding user response:

I can see a bug in your home-routing.ts file. path property in your routes variable contains two extra spaces for HomePage component whereas in app-routing module it is different. You need to remove these two extra spaces.

enter image description here

  • Related