-2

I have two pages, home and player, and i want on the home page to nabvigate to the player page but without being with this format home/player

When i use routerLink="player", it got an error because the link goes to home/player, instead of just player. How can i make that happen?

app-routing module:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {AddPlayerComponent} from './pages/add-player/add-player.component';
import {RouterModule, Routes} from '@angular/router';
import {HomeComponent} from './pages/home/home.component';

const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', component: HomeComponent },
  { path: 'Player', component: AddPlayerComponent }
];


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

2 Answers2

1

Try routerLink = "/Player. Notice how in your defined routing module the "Player" is capitalized, as well as the missing "/" in routerLink. See https://angular.io/api/router/RouterLink for more clarification

0

Try Adding <base href="/"> code in head of index.html page and correct the code to routerLink="/Player".