0

I have just finished updating my app from rc.4 to rc.5 and I'm encountering a weird error.

When I hit localhost:8080 I am redirected to localhost:8080/browse as expected, however when I then hit the browser refresh button I get the following error: Cannot GET /browse.

Note: Before a hash was being added to the URL, i.e. localhost:8080/#/browse but not that doesn't get added.

Here's my routes:

const routes: Routes = [
  {
    component: DashboardComponent,
    path: 'browse'
  }, {
    component: ProductViewportComponent,
    path: 'project/:id'
  }, {
    path: '',
    pathMatch: 'full',
    redirectTo: '/browse'
  }
];

export const routing: any = RouterModule.forRoot(routes);
efarley
  • 8,371
  • 12
  • 42
  • 65

2 Answers2

0

If you use Node.js, then you have to redirect all to index.html file.

app.use('*', function(req, res) {
  res.render('index.html');
});

Don't know if res.render or res.redirect (it is not important though, I just gave you the idea).

by the way, try to edit redirectTo: '/browse' to redirectTo: 'browse'

elzoy
  • 5,237
  • 11
  • 40
  • 65
  • Ahh we actually use webpack and browserify to serve the application not node. We just use node for the package management. – efarley Aug 31 '16 at 19:17
  • Try to hold the main route ``` { path: '', pathMatch: 'full', redirectTo: '/browse' }``` at the top of the routes. I noticed that sometimes routes order is the key. – elzoy Aug 31 '16 at 19:20
  • Nope that doesn't change anything. – efarley Aug 31 '16 at 19:24
0

The problem was caused by me unknowingly changing from the HashLocationStrategy to the PathLocationStrategy

efarley
  • 8,371
  • 12
  • 42
  • 65