简体   繁体   中英

Getting 404 error when Angular HTML5Mode is true

I have implemented pretty url in angular(switched to html5mode).

When I am refreshing the page I get 404 error.

For example: If I open my app using http://server/ , everything works fine,but when I refersh the page or try open specific page ex http://server/mypage , I get 404 error.

Note:

  • When compiling my application I am combining templates in javascript.
  • And after compilation my scripts(with template) goes in build folder and base tag in index.html is set to "/";.

  • I am using Angular-ui-router.

  • Using .net as backend.
  • Frontend app is total separate from backend & both are deployed in IIS.

Please suggest what could be the possible solution or reason for the error.

Thanks

You are should to check your settings in backend, when i am using html5 history, i have for this my .htaccess file (where you redirect all your requests to your root index.php or index.html file), look my .htaccess:

RewriteEngine On  
  # If an existing asset or directory is requested go to it as it is
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ - [L]

  # If the requested resource doesn't exist, use index.html
  RewriteRule ^ /index.html

if this not help, you are can to read this [article]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM