0

This is my working router in the dev environment.

const WEBAPP_ROUTES: Routes = [
  { path: 'feed', component: LiveFeedComponent},
  { path: 'register-line', component: RegisterLineComponent},
  { path: 'rides', component: RidesComponent},
  { path: 'track', component: TrackPageComponent},
  { path: 'settings', component: SettingsComponent},
  { path: 'user', redirectTo: 'user/'+localStorage.getItem('username'), pathMatch: 'full'},
  { path: 'user/:id', component: ProfileComponent}
];

However it break after AoT build, and gives this output, when trying to access the web app.

Uncaught Error: Invalid configuration of route 'user'. One of the following must be provided: component, redirectTo, children or loadChildren

I've tried defining the routes in childs like this: (which also worked with the dev enviroment).

const WEBAPP_ROUTES: Routes = [
// { path: '**', redirectTo: 'feed', pathMatch: 'full'},
  { path: 'feed', component: LiveFeedComponent},
  { path: 'register-line', component: RegisterLineComponent},
  { path: 'rides', component: RidesComponent},
  { path: 'track', component: TrackPageComponent},
  { path: 'settings', component: SettingsComponent},
  { path: 'user', children: [
        { path: '', redirectTo: localStorage.getItem('username'), pathMatch: 'full' },
        { path: ':id', component: ProfileComponent }
    ]}
];

How come the error messages doesn't even make sense?

EDIT: Related github discussion: link

Jonas Praem
  • 2,296
  • 5
  • 32
  • 53
  • 'One of the following must be provided: component, redirectTo, children or loadChildren' is that not provided? and runtime route config? – Jonas Praem Jan 19 '18 at 23:17
  • Are you not getting the `username` item from `localStorage` at runtime? Therefore, AOT becomes problematic. If the compiler can't resolve the value *ahead-of-time*, then it thinks it has not been provided. – R. Richards Jan 19 '18 at 23:21
  • how would i get runtime information to the router then? - If I want to do the desired redirect? url/user redirects to the user's own profile. – Jonas Praem Jan 19 '18 at 23:30
  • I want to say just have the `ProfileComponent` component read the `username` item from `localStorage` directly. I would think that would do the trick. Do you really need to pass the value on the URL when you have it stored? – R. Richards Jan 19 '18 at 23:35
  • I want their routing to be unique. so user/user1 and user/user2 are served as a profile lookup. redirecting is for redirecting to user's own profile – Jonas Praem Jan 19 '18 at 23:40

0 Answers0