Search code examples
angularionic-frameworkangular-routing

Ionic: Error: Cannot match any routes. URL Segment:


I'm trying to create a relatively basic Ionic application but I'm getting the error:

core.js:14597 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'match-details/match-details-info'
Error: Cannot match any routes. URL Segment: 'match-details/match-details-info'
    at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirects.noMatchError (router.js:2469)

What I'm trying to do is on click of a button on a regular page is move to another page that has tabs on the page.

I am moving from http://localhost:8100/tabs/fixtures to what I would expect to be http://localhost:8100/match-details/match-info but instead I am getting the above error and I stay on the original page.

Here is a segment of my app-routing.module.ts file showing the match-details path (line 3):

const routes: Routes = [
  { path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
  { path: 'match-details', loadChildren: './pages/match-details/match-details.module#MatchDetailsPageModule' },
  { path: 'match-details-standard/:id', loadChildren: './pages/match-details-standard/match-details-standard.module#MatchDetailsStandardPageModule' },
  { path: 'player-details/:id', loadChildren: './pages/player-details/player-details.module#PlayerDetailsPageModule' },

And here is my match-details-routing.module.ts:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MatchDetailsPage } from './match-details.page';

const routes: Routes = [
  {
    path: 'match-details',
    component: MatchDetailsPage,
    children: [

      {
        path: 'match-details-info',
        children: [
          {
            path: '',
            loadChildren: '../match-details-info/match-details-info.module#MatchDetailsInfoPageModule'
          }
        ]
      },
      {
        path: 'match-details-lineup',
        children: [
          {
            path: '',
            loadChildren: '../match-details-lineup/match-details-lineup.module#MatchDetailsLineupPageModule'
          }
        ]
      },
      {
        path: '',
        redirectTo: '/match-details/match-details-info',
        pathMatch: 'full'
      }
    ]
  },
  {
    path: '',
    redirectTo: '/match-details/match-details-info',
    pathMatch: 'full'
  }
];

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

Driving me crazy!!!!!!!!


Solution

  • From what I can see your routes are set up in such a way that the path would be match-details/match-details/match-details-info due to both route paths including the match-details

    try changing your routes in the match-details-routing.module.ts as below

    const routes: Routes = [
      {
        path: '',
        component: MatchDetailsPage,
        children: [
          {
            path: 'match-details-info',
            children: [
              {
                path: '',
                loadChildren: '../match-details-info/match-details-info.module#MatchDetailsInfoPageModule'
              }
            ]
          },
          {
            path: 'match-details-lineup',
            children: [
              {
                path: '',
                loadChildren: '../match-details-lineup/match-details-lineup.module#MatchDetailsLineupPageModule'
              }
            ]
          },
          {
            path: '',
            redirectTo: '/match-details/match-details-info',
            pathMatch: 'full'
          }
        ]
      }
    ];