Running Angullar 2 on http-server

Asked

Viewed 36 times

0

I have an application in Angular2 and was generated /dist where it contains the HTML, CSS and Javascript code executed the code using http-server and Tomcat. My problem is when I turn my routes, it’s like this -> http://localhost:4201/Dashboard but the problem is when I refresh the page it does not find because it would have to add '#/' example: http://localhost:4201/#/Dashboard

  • You disabled the routes in Html5 mode?

  • How do I disable?

2 answers

0

I was able to solve by adding into the /dist . htaccess folder <IfModule mod_rewrite.c> Options Indexes FollowSymLinks RewriteEngine On RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </IfModule>

0

To use routes without HTML5 mode, using hashbang, you need to do this configuration in your main route module:

...
imports: [
  ...
  RouterModule.forRoot(routes, { useHash: true })
  ...
]
...

According to doc: Appendix: Locationstrategy and browser Styles URL

  • It used this way, but when generating the build stopped working.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.