javascript - AngularJS html5mode reloading page -
i have 2 separate applications:
- angularjs client working on http://localhost:8080
- nodejs api server working on http://localhost:3000
nodejs api server gives json data client (and not give html pages). so, provide client ability communicate server, enable cors technology on api server.
app.use(function(req, res, next) { res.header("access-control-allow-origin", "*"); res.header("access-control-allow-headers", "origin, x-requested-with, content-type, accept"); res.header('access-control-allow-methods', 'get,put,post,delete,options'); next(); });
also want use clean urls without # symbol, enable html5mode in angularjs app
function config($stateprovider, $urlrouterprovider, $locationprovider) { $locationprovider.html5mode(true); $urlrouterprovider.otherwise('/login'); ...
---index.html
<!doctype html> <html lang="en" ng-app="app"> <head> <base href="/"> <title>app</title> <link rel="stylesheet" href="css/normalize.css"> <link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="css/fontello.css"> </head> <body> <div ui-view="content"></div> <script src="dist/app.js" type="text/javascript"></script> </body> </html>
the problem: when interact app btn's ui-sref
working good, when reload page, following output: cannot /about
you can suggest me use rewrite links index.html example:
app.all('/*', function(req, res, next) { res.sendfile('index.html', { root: __dirname }); });
but haven't "views" on server.
what can offer me in situation?
you guessed right!
you need tell server on port 8080 serve index.html file on requests (other existing static files).
ui router route relevant page client-side on angular app or redirect user url if 1 typed not valid route.
Comments
Post a Comment