I have write my first webapp with angular2.
I have implemented jwt token, so when user access to localhost/mysite
arrive to
Login page with this route localhost/mysite/login
, but if I refreh page it return 404 error.
I tried and the problem is also in "heroes-example" of angular documentation.
How can I avoid problem because if I open site with npm start it work, but if I would put this in production this Is a problem.
Asked
Active
Viewed 311 times
0

LorenzoBerti
- 6,704
- 8
- 47
- 89
-
Are you defining base href? Where are you deploying your application? – Patriicya Nov 29 '16 at 23:25
-
Yes href Is defined, I haven't deploy . What can I use for deployment withouth angular-cli ? Because I haven't already start project and now Angular-cli doesn't work. – LorenzoBerti Nov 30 '16 at 07:12
1 Answers
1
The problem is not coming from Angular directly but from your WebServer configuration, you will need to add a Rewrite rule to redirect every request (except eventually /api and others non related endpoint) to your index file. It will fix the issue.
Since the Router module is based on the History browser API, it's working great to change the url in the address bar, but if you press F5, you are just loading a page that does not exist. By redirecting everything to the index page, you let Angular handle the URL properly and return the good component.

LoïcR
- 4,940
- 1
- 34
- 50
-
I have the same problem. So, should I have to add something like the base app? such as : provide(APP_BASE_HREF, { useValue: '/SiteA' }).., ?? – Celso Agra Nov 30 '16 at 00:33
-
Ok, so with simething like .htaccess . I tried but it Is ignored but it Is probably a problem of my server . But for building app for deploy what can I do if I haven't installed angular-cli? – LorenzoBerti Nov 30 '16 at 07:07