I have been the whole day trying to figure out how can I load a new page in Angular 9, like when you click, and you can see that you are being redirected to a new page. I have seen the following relevant links, none of which has solved my question:
- Angular 4 not loading component
- https://angular.io/guide/router
- How to navigate to other page in angular 6?
- https://www.techiediaries.com/angular-router-routerlink-navigate-navigatebyurl/
I have successfully achieved a not-wanted behavior, in which the components are loaded on the same page instead of on a new page.
This is my app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { CreateQueueComponent } from './create-queue/create-queue.component';
import { SubscribeQueueComponent } from './subscribe-queue/subscribe-queue.component';
import { AppRoutingModule } from './app-routing.module';
import { ManageQueueComponent } from './manage-queue/manage-queue.component';
@NgModule({
declarations: [
AppComponent,
CreateQueueComponent,
SubscribeQueueComponent,
ManageQueueComponent
],
imports: [
BrowserModule,
FormsModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
This is my app-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CommonModule } from '@angular/common';
import { CreateQueueComponent } from './create-queue/create-queue.component';
import { ManageQueueComponent } from './manage-queue/manage-queue.component';
import { SubscribeQueueComponent } from './subscribe-queue/subscribe-queue.component';
const routes: Routes = [
{ path: 'createQueue', component: CreateQueueComponent },
{ path: 'manageQueue', component: ManageQueueComponent },
{ path: 'subscribeQueue', component: SubscribeQueueComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
As the documentation suggest, I have made sure in my index.html
I have the <base href="/">
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.2/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
</head>
<body>
<app-root></app-root>
</body>
</html>
This is my app.component.html
...
<a class="circle-link option-card" title="Join" routerLink="/subscribeQueue">
<i class="fas fa-calendar"></i>
<span>Subscribe</span>
</a>
...
My <router-outlet>
is appended at the end of the app.component.html
. So the question would be, how can I replace the content or partial content of the web with the one on the target component?
Does anyone know what's going on? Am I missing something here?
Thank you.