Error Encountered in Angular 2 Routing - No Matching Routes Found in URL Segment

After spending more than 7 days on this issue, I am at a loss. No matter how hard I try, I can't seem to get it to work. Every time I include the path to the template in the children, it results in an error and crashes the application.

Here's the code snippet:

export const routes: Routes = [
{path: 'store', component: StoreComponent, 
    children: [
          {path: 'apple', component: AppleComponent}
    ]
}

AppleComponent.ts

import {Component, OnInit, Type} from '@angular/core';
import {Router, ActivatedRoute} from "@angular/router";

@Component ({
    selector: 'apple',
    templareUrl: '../apple.html
})

export class AppleComponent implements OnInit {
     constructor(){}

     nGOnInit():void{}
}

I have included <base href="/"> in the index.html file but unfortunately, that didn't resolve the issue.

As a beginner in Angular2, I hope you all can forgive any naive questions I may ask.

EDIT: The placement of this code is crucial within the children due to the use of router-outlet.

Thank you for your help.

Answer №1

If you want to include the AppleComponent in your routing, you have a couple of options:

{ path: 'store/apple', component: AppleComponent, pathMatch: 'full' }

Or, you can try this approach instead:

export const storeChildrenRoutes: Routes = [
  {
    path: 'store',
    component: StoreComponent,
    children: [
      {
        path: 'apple',
        component: AppleComponent,
      }
    ]
  }
];
@NgModule({
  imports: [
    RouterModule.forChild(storeChildrenRoutes)
  ],
  exports: [
    RouterModule
  ]
})
export class StoreChildRoutingModule {}

Create a separate module for this and import it into your main AppRouting module that contains your primary routes like so:

RouterModule.forRoot(appRootRoutes)

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

What is the process for removing a record from a table using Angular's http.delete method with a PHP backend

I'm attempting to remove a record from the database table using Angular on the front end and PHP on the back end. I'm passing the id through the URL and trying to retrieve it with $_GET['id'], but it's not working (no errors in the ...

What exactly does the syntax (<any> new Classname) accomplish in terms of purpose and behavior?

In the code snippet below, a new instance of ClickerApp is being created with a PlatformMock and MenuMock as parameters: let instance = new ClickerApp((<any> new PlatformMock), (<any> new MenuMock)); This code example is taken from the follow ...

What is preventing me from setting a background image in Angular 13?

Trying a different approach based on advice from Stack Overflow, I attempted the following: <div [style.background-image]="'url(https://picsum.photos/200)'"></div> Unfortunately, this resulted in no effect and the image was ...

Can you explain the purpose of the .subscribe() function?

Currently, I am in the process of developing an API using Angular2 and NodeJS. My focus has been on implementing services for my API that are responsible for retrieving a list of tasks and presenting them. Below is the code snippet for the task service: i ...

Exploring the concept of individuality within front-end development

Would it be possible to manage identity directly on the front end using Angular's auth guard instead of setting up identity management on the server-side? The auth guard could handle all aspects of identity, even for smaller projects. For instance, in ...

Angular Component Disappearing from View

While working on an angular project, I encountered a situation where the Index.HTML file in the src folder was being displayed instead of the app-component. I searched for various solutions, but none seemed to work. import { NgModule } from '@angular ...

Angular: Dynamic component visibility based on sibling component's state

On a webpage, I have both a checkbox and a textbox. The checkbox and textbox are separate components that function independently of each other. The textbox should remain hidden until the checkbox is activated. If the checkbox is turned off, the textbox sh ...

The ngAfterViewChecked function seems to be caught in an endless loop

I am facing an issue where the <cdk-virtual-scroll-viewport> starts from the bottom, but I am unable to scroll up. I suspect that this problem is related to the use of AfterViewChecked. Even after trying AfterViewInit, the issue persists. @ViewChil ...

Improving Angular's Performance by Handling Absence of Providers for $rootScope and $location

I successfully set up Angular Hybrid configuration using Angular upgrade to enhance performance and the application is running smoothly. However, I am encountering an issue with running test cases on the Angular side. I have provided all the necessary com ...

Utilizing Angular to Handle Undefined Variables in String Interpolation

Seeking a way to showcase data obtained from an external API on a webpage using Angular's string interpolation. If no data is retrieved or is still pending, the aim is to display 'N/A'. An attempt was made following this method, but encoun ...

Angular is utilizing esbuild for integrating ckeditor, but it seems like there is no loader configured for the ".svg"

I am currently using ckEditor and encountering an error when importing a plugin. The specific error message is: No loader is configured for ".svg" files with reference to a file named table.svg located in the node_modules directory. The versions ...

Could someone assist me in identifying the issue with this logfile and guiding me in the correct direction?

Can someone help me troubleshoot the ng e2e issue in my code? Here's a screenshot of the log file: https://i.sstatic.net/PCrab.png I apologize for the formatting of the package.json file. `package.json` file: { "name": "planning", "version": "0. ...

Save geometric shapes data in the SQLite database

How do I go about storing polygon data in an SQLite database? Important: I am utilizing the Cordova plugin. polygon: Point[]; interface Point { x: number; y: number; } https://i.sstatic.net/5EYf2.png ...

Unable to Remove Angular CLI from Ubuntu - Showing `0.083s to check for updates``

I'm having trouble removing Angular from my Ubuntu 18.04 system using the command: npm uninstall -g angular-cli or npm uninstall -g @angular/cli When I try, it just says: up to date in 0.083s Here's a screenshot of the terminal: http ...

Enhancing Angular 17 performance - Integration of AWS URL repeated in server-side rendering for improved HTTP response

In an attempt to transform the API response, I am adding the AWS S3 bucket URL as a prefix to the banner URL from the API side. The transformation works correctly without SSR (Server-Side Rendering). However, when I tested it with SSR, the URL prefix was a ...

Issues with using a personalized font in a Stenciljs project

Looking for guidance on implementing a custom font in my Stenciljs app. I have the otf file, unsure if an npm package is necessary. Here's my code: filestructure: -src --components --assets ---Anurti-Regular.tiff ---Anurti-Regular.ttf friends-l ...

"Develop a unique Angular 12 custom pipe that retrieves data through a service and converts it into a string instead of

Hello Everyone, I've encountered a problem that I need help with. import { Pipe, PipeTransform } from '@angular/core'; import { PrintingTypesService } from 'src/app/settings/services/printing-types/printing-types.service'; import { ...

Service B is receiving query parameters from Service A in a peculiar object format, leaving us puzzled as to the reason behind this unexpected structure

Issue: Encountered a strange bug when our service A (using laravel php) makes a call to an endpoint in service B (built with nodejs typescript + ajv + nestjs). Further explanation of the issue below. Below is an example of code in service A for constructi ...

CORS regulations are preventing access

I have set up an Express server to run my Angular app for server-side rendering purposes. Initially, everything works fine when I make a request from the application. However, an issue arises when I navigate to another page and then return to the previous ...

Importing TypeScript Modules from a Custom Path without Using Relative Paths

If we consider the following directory structure: - functions - functionOne - tsconfig.json - index.ts - package.json - node_modules - layers - layerOne - tsonfig.json - index.ts - index.js (compiled index.ts ...