samedi 3 avril 2021

Angular: What's the purpose of paths in app-routing.module.ts

I'm new in Angular and asked myself what the purpose of the paths in app-routing.module.ts (and so the general purpose of this module) is when all my paths are handled in app.module.ts?

This is my app-routing.module.ts:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { TaskviewComponent } from './taskview/taskview.component';

const routes: Routes = [];

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

This is my app.module.ts:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
import {RouterModule} from '@angular/router';
import { TaskviewComponent } from './taskview/taskview.component';
import { AppRoutingModule } from './app-routing.module';
import { AddTaskComponent } from './add-task/add-task.component';
import {ReactiveFormsModule} from '@angular/forms';

@NgModule({
  declarations: [
    AppComponent,
    TaskviewComponent,
    AddTaskComponent
  ],
  imports: [
    RouterModule.forRoot([{
      path: 'view', component: TaskviewComponent},
      {path: 'add', component: AddTaskComponent
    }]),
    BrowserModule,
    AppRoutingModule,
    ReactiveFormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }



Aucun commentaire:

Enregistrer un commentaire