Home:ALL Converter>How to use routing with module instead of component in Angular 10+

How to use routing with module instead of component in Angular 10+

Ask Time:2020-09-29T17:56:19         Author:sha

Json Formatter

I successfully used component in routing but when i am using module instead of component in angular 10 i am getting a white screen.

I would be really thankful for any kind of help.

this is what i've been trying: app-routing.module.ts

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

import { DashboardModule } from './components/dashboard/dashboard.module';

import { DashboardComponent } from './components/dashboard/dashboard.component';

const routes: Routes = [
    { path: '', loadChildren: () => DashboardModule }
];

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

Dashboard module:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { DashboardComponent } from './dashboard.component';


@NgModule({
  declarations: [
    DashboardComponent
  ],
  imports: [
    CommonModule
  ]
})
export class DashboardModule { }

Dashboard Component:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {

  constructor() { 
    alert('asdf');  
  }

  ngOnInit(): void {
  }

}

Thanks

Author:sha,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/64117210/how-to-use-routing-with-module-instead-of-component-in-angular-10
yy