Upon initial loading, the default sidenav in Angular is not selected

I need to ensure that the sidenav loads the basic page during the initial load. This is controlled by the routing.ts file shown below:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MapGuard } from 'src/app/shared/guards/map.guard';
import { CampaignReportsComponent } from './campaign-reports.component';

const routes: Routes = [
    {
        path: '',
        component: CampaignReportsComponent,
        data: { breadcrumb: 'Campaign-report' },
        redirectTo:'/basic',
        children: [
            {
                path: 'type',
                loadChildren:
                    './campaign-reports-type/campaign-reports-type.module#CampaignReportsTypeModule',
                canActivate: [MapGuard],
                data: { breadcrumb: 'Type' }
            },
            {
                path: 'basic',
                loadChildren:
                    './campaign-reports-basic/campaign-reports-basic.module#CampaignReportsBasicModule',
                data: { breadcrumb: 'Basic' }
            },
            {
                path: 'activity',
                loadChildren:
                    './campaign-reports-activity/campaign-reports-activity.module#CampaignReportsActivityModule',
                data: { breadcrumb: 'Activity' }
            },
            {
                path: 'rewards',
                loadChildren:
                    './campaign-reports-rewards/campaign-reports-rewards.module#CampaignReportsRewardsModule',
                data: { breadcrumb: 'Rewards' }
            },
            {
                path: 'winners',
                loadChildren:
                    './campaign-reports-winners/campaign-reports-winners.module#CampaignReportsWinnersModule',
                data: { breadcrumb: 'Winners' }
            }
        ]
    }
];

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

However, an error is encountered stating

Cannot match any routes. URL Segment: 'basic'

How can this issue be resolved? Any suggestions or insights are greatly appreciated.

Answer â„–1

To properly handle the routing in your application, consider adjusting your routes setup. If you are attempting to access /basic directly, make sure to define it outside of the children array or include a blank path that redirects to the basic route.

 const routes: Routes = [
  {
    path: '',
    component: CampaignReportsComponent,
    data: { breadcrumb: 'Campaign-report' }, 
    children: [
      {
        path: '',
        redirectTo:'/basic',
      },
      {
        path: 'type',
        loadChildren:
          './campaign-reports-type/campaign-reports-type.module#CampaignReportsTypeModule',
        canActivate: [MapGuard],
        data: { breadcrumb: 'Type' }
      },
      {
        path: 'basic',
        loadChildren:
          './campaign-reports-basic/campaign-reports-basic.module#CampaignReportsBasicModule',
        data: { breadcrumb: 'Basic' }
      },
     {
        path: 'activity',
       loadChildren:
          './campaign-reports-activity/campaign-reports- 
       activity.module#CampaignReportsActivityModule',
       data: { breadcrumb: 'Activity' }
     },
     {
        path: 'rewards',
        loadChildren:
        './campaign-reports-rewards/campaign-reports- 
        rewards.module#CampaignReportsRewardsModule',
         data: { breadcrumb: 'Rewards' }
      }, 
         {
            path: 'winners',
            loadChildren:
              './campaign-reports-winners/campaign-reports-winners.module#CampaignReportsWinnersModule',
            data: { breadcrumb: 'Winners' }
          }
        ]
      }
    ];

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

Is there a shortcut for creating interfaces that have identical sub properties?

We are seeking to streamline the interface creation process by utilizing shorthand for properties labeled from Monday through Sunday, each with identical sub-properties. interface Day { start: number end: number } interface Schedule { Monday: Day ...

How to Generate a Collection of Textfields in Angular 4

My challenge involves working with an array object that receives input from a textfield. I am looking to create a clean design where only one textfield is initially displayed, along with a '+' button next to it. When the user enters information i ...

The process of transitioning a fragment into a component

I am trying to dynamically change a fragment of the URL from within a component, but I am encountering difficulties in doing so. <a #linkComponent routerLink='home' fragment='part'>link</a> @ViewChild('linkComponent&a ...

Guide on integrating a newly bought template into an Angular 6 and Bootstrap 4 application

Although I have years of experience as a backend developer, I am relatively new to frontend development. Lately, I have been immersing myself in learning Angular 6 and Bootstrap 4 for an upcoming project at work. After setting up a basic Angular 6 applica ...

What is the best way to create and manage multiple collapsible Material-UI nested lists populated from an array with individual state in React

In my SideMenu, I want each list item to be able to expand and collapse independently to show nested items. However, I am facing the issue of all list items expanding and collapsing at the same time. Here is what I've attempted: const authNavigation ...

Issue with aliasing in tsconfig.app.json not functioning correctly in Angular 11

I'm facing a problem with aliasing after migrating my application to an Angular project. None of my imports are functioning properly with the ""@app"" alias. mainApp │ package.json │ tsconfig.json │ angular.json │ └─┠...

Using RouterLink in a div component with Angular's router version 3.0.0-alpha.3

After declaring a div with routerLink, I realized that it was working fine in previous versions but not anymore in (@angular/router 3.0.0-alpha.3). Has anyone found a solution to this issue? <a class="my-item" [routerLink]="['/hero']">... ...

Typescript - A guide on updating the value of a key in a Map object

My Map is designed to store Lectures as keys and Arrays of Todos as values. lecturesWithTodos: Map<Lecture, Todos[]> = new Map<Lecture, Todos[]>(); Initially, I set the key in the Map without any value since I will add the Todos later. student ...

Can Schema and Model/Entity Files be Decoupled in TypeORM?

Having experience with PHP (Laravel/Eloquent, Symfony/Doctrine), I am accustomed to ORMs not defining schema but making schema attributes accessible. In my previous work, I never had to use a "Model" file to manage schema as it was always handled through m ...

Preventing the conversion of literals to classes in TypeScript

Using TypeScript, you can convert object literals to a class by doing the following: let businessObj = new ScenarioController(<FormatService>{ format: x => x }); Is there a way to prevent these types of casts in the compiler or linter? Oft ...

Get a single object from an array with .single method provided by @ngrx

Seeking to retrieve an Observable containing a single object from an array of objects in my store. I aim to utilize the .single operator, which should throw an exception if there is not exactly 1 object present. However, I'm struggling with this as my ...

Unlocking the secrets of integrating Vuex store with JavaScript/TypeScript modules: A comprehensive guide

I am working on a vue application and I have a query. How can I access the store from javascript/typescript modules files using import/export? For example, if I create an auth-module that exports state, actions, mutations: export const auth = { namesp ...

Tracking user session duration on a React Native app can be achieved by implementing a feature that monitors and

I'm currently focusing on tracking the amount of time a user spends on the app in minutes and hours, and displaying this information. I have successfully implemented the functionality to count minutes, but I am struggling to figure out how to track wh ...

Generate a custom string to reference a JSON object containing a variable from an Angular HTML document

I am trying to generate a string within my HTML file to access data from a JSON object. HTML File <app-banner></app-banner> <section id="mail-view" class="bg-gray" > <div class="container"> <figure id="state-stats" class= ...

Executing a PHP function within a Laravel controller using Ajax

In my Laravel project, I have a Controller named Clientecontroller that is working perfectly. It contains a method called listar() which retrieves client information. public function listar(Cliente $cliente) { $clientes = DB::table('clientes' ...

Preserve data on page even after refreshing in Angular

Upon opening my website, I expect to see "Finance/voucher" at the top. However, after refreshing the page, only "Finance" appears which is not what I want. I need it to always display "Finance/voucher" even after a page refresh. I have included all the r ...

Storing a value in a variable using ngFor in Angular 4

Here is the code snippet I am working with: <ng-container *ngFor="let item of items"> <div>{{item.subArray[0].attr1}}</div> <div>{{item.subArray[0].attr2}}</div> </ng-container> I am wondering if it's possible to ...

Troubleshooting issue: matTooltip malfunctioning in *ngFor loop after invoking Angular's change

The matTooltip in the component below is rendering correctly. The overlay and small bubble for the tooltip are rendered, but the text is missing (even though it's present in the HTML when inspecting in the browser) and it isn't positioned correct ...

What are the TypeScript type definitions for the "package.json" configuration file?

What is the most efficient method for typing the content of the "package.json" file in TypeScript? import { promises as fs } from 'fs'; export function loadManifest(): Promise<any> { const manifestPath = `${PROJECT_DIR}/package.json`; ...

Eliminating the dynamic element in jQuery causes disruption to the ViewContainerRef container

In my Angular 2+ application, I am dynamically creating components using the following code snippet: @ViewChild("containerNode", { read: ViewContainerRef }) cardContainer; const factory = this.ComponentFactoryResolver.resolveComponentFactory(CardComponen ...