Issue: Encountered an uncaught error while attempting to match routes in Angular 6 due to an invalid URL segment

I am currently developing an application using Angular 6. I have a login page and I am trying to redirect from the login page to the dashboard page. I have added routing in the app.component.ts file, but I encountered an error stating "Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'dashbaord'". Can someone please point out where I went wrong?
app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LogingComponent } from './loging/loging.component';
import { SidebarComponent } from './sidebar/sidebar.component';
import { DashboardComponent } from './dashboard/dashboard.component';
@NgModule({
  declarations: [
    AppComponent,
    LogingComponent,
    SidebarComponent,
    DashboardComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }


login.component.ts

import { DashboardComponent } from './../dashboard/dashboard.component';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-loging',
  templateUrl: './loging.component.html',
  styleUrls: ['./loging.component.css']
})
export class LogingComponent implements OnInit {
  constructor(private router: Router) { }
  public onLoginClick() {
    console.log('Hi');
    this.router.navigate(['./dashbaord']);
}
  ngOnInit() {
  }
}


app.routing.module.ts

import { NgModule, Component } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard/dashboard.component';
import { LogingComponent } from './loging/loging.component';
const routes: Routes = [
  { path: '', component: LogingComponent},
  { path: 'dashboard', component: DashboardComponent}
 ];    
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }


dashboard.component.ts

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

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

  constructor() { }

  ngOnInit() {
  }

}

Answer №1

Your party gets spoiled by a login typo.

Swap

this.router.navigate(['./dashbaord']);

With...

this.router.navigate(['./dashboard']);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

HttpClient experiences a timeout in processing the request

Currently, I am utilizing TypeScript in conjunction with ASP.NET Core Web API. Situation: I am facing a challenge with a backend data response service that is taking more than two minutes to load the data. It appears that the default timeout for the Http ...

Error message: "Mismatched data types in Formik errors when utilizing TypeScript"

I have a customized input component for formik which includes an error label if one exists. When I print it like this: {errors[field.name]}, it works. However, {t(errors[field.name]?.toLocaleString())} does not work. import { FieldProps, FormikErrors } ...

How to display the current date with the correct format using Angular 2?

I am trying to display the current date in the correct format, for example: 12/19/2016. I am currently using Date.now() but it is showing a garbage value. I only want to display the date without the time. I have also tried using pipes, but they are not b ...

How can React be used to constantly update a string whenever a checkbox is ticked, and subsequently show this updated string in a separate input field

I need to dynamically update a text input field each time a checkbox is checked as true. Could someone provide guidance on how to achieve this? My goal is to have a checkbox trigger an update in another input field. When the checkbox is checked, I want to ...

Leveraging TypeScript Declarations for an External JavaScript Library

Struggling to find clear documentation on how to properly use the ALKMaps JavaScript library in my Ionic application. I created a local npm module with an alkmaps.d.ts file, but I can't seem to import it into my Angular code without encountering error ...

Here's how you can combine several elements from one array and assign them to the first element of another array:

I'm working with an array that looks like this: public static readonly List: Array<any> = [ { name: 'CCS', link: 'Dummy link1' }, { name: 'CCR', link: 'Dummy link2' }, { name: 'PM', ...

Is it considered a poor practice to self-instantiate within a static method of a JavaScript class

Do you think this object-oriented JavaScript (TypeScript) code is not well-written? class KYC { public reference; public data = null; constructor(id: string) { this.reference = id ? firestoreAdmin.collection('kyc').doc(id) : fi ...

When a card is clicked in the parent component, data is sent to the child component in Angular. The card contains an image, name, ID,

How can I pass data from a parent component (nfts) to a child component (main) when a card is clicked? The card contains images, ids, names, and more information. I've attempted using @Input() but haven't been able to receive the value in the ch ...

Tips for determining if an array of objects, into which I am adding objects, contains a particular key value present in a different array of objects

I've been working on this and here is what I have tried so far: groceryList = []; ngOnInit() { this._recipesSub = this.recipesService.recipes.subscribe((receivedData) => { this.loadedRecipes = receivedData.recipes; }); } onCheckRecipe(e) { ...

Convention for Naming Files in Typescript

Can anyone provide guidance on file-naming conventions specifically for a Typescript file dedicated to storing types and interfaces? I have come across various Typescript Coding Convention projects on GitHub which cover general file-naming conventions her ...

Is it advisable to pass useSelector to useState in React?

Hey everyone, I've got a question about preferences for a specific method: When working with a React functional component in TypeScript that retrieves values from Redux State using useSelector, which approach do you prefer? 1) const campaign = us ...

Challenge encountered when setting new values to an object depending on its existing values

I am facing an issue with a data object that stores values and their previous values. The keys for the previous values are suffixed with ":previous" e.g. foo and foo:previous. However, I encountered a type error when trying to assign values to the previous ...

TypeScript's reusable retry functionality

This specialized function takes an input function as its first argument and a set of customizable options as its second. It repeatedly calls the provided function, retrying until either a successful result is returned or the maximum number of attempts is r ...

What is the best way to utilize "exports" in package.json for TypeScript and nested submodules?

Looking to leverage the relatively new "exports" functionality in Node.js/package.json for the following setup: "exports": { ".": "./dist/index.js", "./foo": "./dist/path/to/foo.js" } so that ...

Issue - The path to the 'fs' module cannot be resolved in ./node_modules/busboy/lib/main.js

After adding a new React component to my NextJS app, I encountered a mysterious error in my local development environment: wait - compiling... error - ./node_modules/busboy/lib/main.js:1:0 Module not found: Can't resolve 'fs' null Interest ...

Unresolved Axios jsonp request causing code blockage

Recently, I created a function to retrieve Google suggestions: const fetchGoogleSuggestions = async (searchQuery: string) => { const results = await axios({ url: `https://suggestqueries.google.com/complete/search?client=chrome&q=${searchQuery ...

Error during Next.js build: Incompatible types - cannot assign type to 'never'

Encountering an error in the console while attempting to build my project: .next/types/app/facebook/page.ts:8:13 Type error: Type 'OmitWithTag<typeof import("D:/projects/abkh24/client/app/facebook/page"), "metadata" | "defa ...

Guide on properly defining typed props in Next.js using TypeScript

Just diving into my first typescript project and finding myself in need of some basic assistance... My code seems to be running smoothly using npm run dev, but I encountered an error when trying to use npm run build. Error: Binding element 'allImageD ...

Creating a build task in Visual Studio Code with universal TypeScript compiler settings

Our project has the following structure: +-- views +-- viewXXX +-- ts ¦ +-- controller.ts ¦ +-- helper.ts ¦ +-- ... (*.ts) +-- viewXXX.ctrl.js // this is the desired output file +-- viewXXX.c ...

The error message "external.js: $ is not defined" indicates that

Recently, I integrated an external JavaScript file into my Angular 14 project. This JS file contains the event $('.class').click(). However, every time I launch the application on localhost, a message pops up in the browser stating that $ is not ...