Question:
Why Angular routing with mat-toolbar is not working?

Problem

I am trying to call up 3 different tabs using angular-routing. I use a mat-toolbar for the display. I followed the steps from a youtube tutorial >https://www.youtube.com/watch?v=ADEZTrIxj1k&ab_channel=TechnophileProgBox .


While I was programming, the navigation worked with a component. Now it no longer works with any of them.


I have searched for a solution on Stackoverflow and found nothing, can you please help me?


app.component.html


<app-navbar></app-navbar>

<router-outlet></router-outlet>


navbar.component.html


<mat-toolbar color="primary" class="mat-elevation-z8">

    <span><mat-icon>euro_symbol</mat-icon> Rechnungen</span>

    <div class="spacer"></div>

    

    <a mat-button router-link="/customers">Kunden</a>

    <a mat-button router-link="/articles">Artikel</a>

    <a mat-button router-link="/invoices">Rechungen</a>


</mat-toolbar>


app-routing.module.ts


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

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

import { CustomersComponent } from './customers/customers.component';

import { InvoicesComponent } from './invoices/invoices.component';

import { ArticlesComponent } from './articles/articles.component';


const routes: Routes = [

  {path: 'invoices', component:InvoicesComponent},

  {path: 'articles', component:ArticlesComponent},

  {path: 'customers', component:CustomersComponent}

];


@NgModule({

  imports: [RouterModule.forRoot(routes)],

  exports: [RouterModule]

})

export class AppRoutingModule { }


app.module.ts


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

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


import { AppRoutingModule } from './app-routing.module';

import {MatToolbarModule} from '@angular/material/toolbar';

import {MatButtonModule} from '@angular/material/button';

import {MatIconModule} from '@angular/material/icon';


import { AppComponent } from './app.component';

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { NavbarComponent } from './navbar/navbar.component';

import { ArticlesComponent } from './articles/articles.component';

import { InvoicesComponent } from './invoices/invoices.component';

import { CustomersComponent } from './customers/customers.component';



@NgModule({

  declarations: [

    AppComponent,

    NavbarComponent,

    ArticlesComponent,

    InvoicesComponent,

    CustomersComponent

  ],

  imports: [

    BrowserModule,

    AppRoutingModule,

    BrowserAnimationsModule,

    MatToolbarModule, //import mattoolbar 

    MatButtonModule,

    MatIconModule

  ],

  providers: [],

  bootstrap: [AppComponent]

})

export class AppModule { }


Solution

It seems like you have a typo: router-link should be routerLink


Suggested blogs:

>How to make the dropdown for this button ADA accessible in Angular?

>How to update properties value with event in template Angular?

>Unit Test Angular Standalone Component, Overriding Provider not used

>How to Import componet's own module using Angular?

>Why component does not display variable of another component in Angular?

>What are the ways to pass parameters to Angular service?

>How to access variables in a function using Angular?

Nisha Patel

Nisha Patel

Submit
0 Answers