1

I have created routes like this

{path: 'trainings', component: TrainingWrapperComponent,
  children:[
    {path: '', component: TrainingsListComponent},
    {path: 'createTraining', component: ManageTrainingComponent},
    {path: 'trainingLanguage', component: TrainingLanguageComponent},

  ]
  },

Now when I navigate to child route from trainings, I am able to do it. But if I refresh or I try to open the url directly. I am not able to do that.

For instance trainings/createTraining is throwing http errors because it is trying to fetch resources by taking training/ as the base url .

Pratik Barasia
  • 561
  • 1
  • 3
  • 14
  • May you post the code part where the route is called please ? – Alexis Le Gal Aug 31 '16 at 14:20
  • I don't see anything wrong. You have: in the index.html? Isn't it the webserver than doesnt understand the routes. Does it also occur when you use HashLocationStrategy? – Marcel Hoekstra Aug 31 '16 at 14:46
  • I am navigating like this: It works from here, but a refresh after navigation doesnt work and also when I try to navigate to localhost/trainings/createTraining, it doesnt work as well – Pratik Barasia Sep 02 '16 at 06:15
  • @MarcelHoekstra yes I have base href defines in index.html. Also I am currectly using browsersync to run my project. Can that be an issue? – Pratik Barasia Sep 02 '16 at 07:35

1 Answers1

4

Ok. I finally found the solution. The problem was that the server was not able to recognise my child routes as part of the angular route and thus that error. So, the simplest solution was to change the location strategy used for routing to hashlocationstategy. This immediately solved the problem.

Pratik Barasia
  • 561
  • 1
  • 3
  • 14