Q: When you refresh the page, what really happens?
A: You send an HTTP request through your browser to the server. GET /whatever . Thus, the server will need to configure the route for this request, which responds with index.html . You are currently getting 404 because your server does not have a route that matches the GET /whatever request.
Q: Why?
A: When you make a request through your browser (and not through AJAX), your browser will try to display a response to you. Ex. if the response is JSON, it will show you JSON. If it is a string, it will show you a string. If this is an html page, this will show you this. You cannot simply send a template for any route, because if you do, it will simply display this template without any other context. You need index.html download angular, launch your controller, put the ui-view template in it, etc.
(What happens is that index.html will be sent, the UI Router will check the route, execute the request for templateUrl , start the controller, and then display it.)
Q: How?
A: It depends on what type of server you are using, and b) the structure of your file. You will probably need some way to catch the entire route at the end of your route file, which serves index.html . Here's how I do it with Node / Express:
app.get('/*', function(req, res) { var url = path.resolve(__dirname + '/../client/index.html'); res.sendFile(url, null, function(err) { if (err) res.status(500).send(err); else res.status(200).end(); }); });
source share