I just start learn Angular2, and I want run writed application on Apache server, but my index file don't work like that from tutorial : https://angular.io/guide/quickstart
Asked
Active
Viewed 1,605 times
4
-
1Welcome to StackOverflow. This is not enough information to be able to provide any support or an answer. Please explain at least what "don't work" means. Do you get any error message? A guess is http://stackoverflow.com/questions/31415052/angular-2-0-router-not-working-on-reloading-the-browser – Günter Zöchbauer Mar 21 '16 at 06:37
-
It's possible to run angular2 on apache2 ? In every tutorial this apps are running by 'npm start' – Romek Krzymek Mar 21 '16 at 07:01
-
You can serve Angular with any web server. You might need to switch back to `HashLocationStrategy` if the server doesn't support HTML5 pushState. I don't have much experience with configuring Apache but I'm sure it does support it and there are answers out there how to configure it. If it doesn't work, try to use `HashLocationStrategy`. After you got it working with `HashLocationStrategy` you can try to make it work with HTML5 pushState (`PathLocationStrategy` in Angular2 - which is the default). – Günter Zöchbauer Mar 21 '16 at 07:04
1 Answers
0
ng2 apps are SPAs (Single page apps).
Thus we must deliver index.html (our single page) on each request.
If we are not doing this then our app will load OK initially but when we change route and click refresh we get a 404 or some other error.
Typicaly rules for a server for an ng2 SPA will look something like ..
^/api/(.*)$ http://localhost:51108/api/$1 [P]
^[^\\.]*$ /index.html [L]
The first line here rewrites all requests starting with /api to our API server.
The second line causes all other requests to serve index.html - this is how we achieve our SPA
The exact syntax of these rules may vary but this info should point you in the right direction to help you resolve this issue.

danday74
- 52,471
- 49
- 232
- 283