0

I've turned off my # using html5 mode in Angular.js and am using grunt and node as a dev server however reload and refresh come back as 404.

How do you enable the node server in Grunt to do page reloads?

2
  • have you used base href in the main html template. Commented Dec 8, 2015 at 6:20
  • Yes I have..I have set it to / Commented Dec 8, 2015 at 7:15

1 Answer 1

1

Say your application entry point is http://localhost/app/. You enter this page into the browser's address bar, the browser sends a request, the server finds the file app/index.html in its document root and returns it. Now the browser finds some script tags in that document, requests the scripts from the server and executes them. Your application is working.

At one point angular-route jumps in and starts manipulating the browser's address bar. At one point it may display http://localhost/app/shop/order there. Now you hit reload. What happens? Just read this answer from the beginning but with the modified URI:

... the server does not find the file app/shop/order/index.html and responds with a 404.

You cannot get rid of the hash sign without configuring the server. From https://docs.angularjs.org/guide/$location:

Server side

Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html). Requiring a <base> tag is also important for this case, as it allows Angular to differentiate between the part of the url that is the application base and the path that should be handled by the application.

How should the server know that /app/shop/order is essentially a request for /app but /app/app.js or /app/partials/overView.html are requests for real files? You have to configure the server for that and you often have to restructure your application.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.