0
votes

I just get error called by redirect code, but I should get redirect with my code:

  if (!localStorage.getItem('emp_user')) {
        console.log('HELLO THERE');
        this.router.navigate(['create'])
      } 

And also Error that I get:

core.js:5847 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'split' of undefined TypeError: Cannot read property 'split' of undefined at defaultUrlMatcher (router.js:530) at match (router.js:2718) at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirects.matchSegmentAgainstRoute (router.js:2564) at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirects.expandSegmentAgainstRoute (router.js:2515) at MapSubscriber.project (router.js:2488) at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:35) at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:53) at Observable._subscribe (subscribeToArray.js:5) at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:43) at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:29) at resolvePromise (zone.js:852) at resolvePromise (zone.js:809) at zone.js:913 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423) at Object.onInvokeTask (core.js:24328) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195) at drainMicroTaskQueue

UPD: Routes

App.routing

const routes: Routes = [
  {
    path: '',
    redirectTo: 'dashboard',
    pathMatch: 'full',
  }, {
    path: '',
    component: AdminLayoutComponent,
    children: [{
      path: '',
      loadChildren: './layouts/admin-layout/admin-layout.module#AdminLayoutModule'
    },
  ]
  },
  {
    path: '',
    loadChildren: './_user/user.module#UserModule'
  },
  // {path: '**', redirectTo: 'default/error/403', pathMatch: 'full'},
];

@NgModule({
  imports: [
    CommonModule,
    BrowserModule,
    RouterModule.forRoot(routes, {
       useHash: true
    })
  ],
  exports: [
  ],
})
export class AppRoutingModule { }

Admin-layout.routing

import { Routes } from '@angular/router';

import { DashboardComponent } from '../../dashboard/dashboard.component';

export const AdminLayoutRoutes: Routes = [
    { path: 'dashboard',      component: DashboardComponent },
    { component: ConfirmDialog }
];

user.routing

export const UserRoutes: Routes = [
    {
        path: '',
        component: UserComponent,
        children: [
            {
                path: '',
                redirectTo: 'create',
                pathMatch: 'full'
            },
            {
                path: 'create',
                component: RegistrationComponent
            },
        ]
    }
];
1
can you show us the routerModule fileGhoul Ahmed
Try with this.router.navigateByUrl("/user/create") assuming your url existsRobert garcia
@Robertgarcia no, it's not work :(msmrc
@GhoulAhmed well, I addedmsmrc
The route you are trying to access doesnt looks like it exists, you have /create route, but you dont have /user/create routeRobert garcia

1 Answers

0
votes

change this path (app.routiing.ts)

{
   path: '',
   loadChildren: './_user/user.module#UserModule
}

to

{
   path: 'user',
   loadChildren: './_user/user.module#UserModule
}