4

I 've just update my project to version rc 4 and got the problem.

When I use the systemjs to config my project, everything is ok.

When I run the project with webpack (I am using the angular2-webpack-starter ) the project was run successfully, no bugs. I can go to every link which was config by [routerLink].

But with the same link if I type the url to the browser's address bar. There was nothing happened. My app did not load anything. Here is some screen shot from my project:

Screen shot

Can anyone help me? I am thank you so much.

Giang Đỗ Hoàng
  • 137
  • 1
  • 1
  • 8
  • Your link isn't public, please host your screenshot at some public site like imgur, or adjust your google settings. Anyway, it seems like you are missing `` in your index.html – Harry Ninh Jul 19 '16 at 09:12
  • Sorry,the link is public now. I 've already put the in the of the index.html – Giang Đỗ Hoàng Jul 19 '16 at 09:17

2 Answers2

4

This needs to be handled by your back-end server.

You need to send all requests to the index page so that Angular can pick up the request and resolve the route from there.

What's happening is when you visit your index(/) page Angular takes over and when you click on a [routerlink] it pretends to change the page in the browser (it's not actually doing anything with the server). When you visit any page that isn't the index by typing in the URL then you are not loading your Angular app and therefore it's not able to edit routes in the browser. By forwarding all routes to the index we're letting Angular decide how all routes should be handled, instead of the server.

Andy-Delosdos
  • 3,560
  • 1
  • 12
  • 25
0

Ìf you serve the content by JS. Add this code to express route

var path = require('path')

app.get('/*', function(req, res) {
  res.sendFile(path.join(__dirname + '/static/index.html'));
});
Gia Ho
  • 1
  • 1
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – DimaSan Mar 11 '17 at 10:12