javascript - Browser triggered reload inside SPA with angular routing -
javascript - Browser triggered reload inside SPA with angular routing -
i have angular spa beingness served node, whenever refresh / reload non root page, express based server intercepts route , returns "cannot route_x". functionality missing routes enable refresh behavior?
angular.module('approutes', []).config(['$routeprovider', '$locationprovider', function($routeprovider, $locationprovider) { $routeprovider .when('/', { templateurl: 'views/nests.html', controller: 'nestcontroller' .when('/pair/:id', { templateurl: 'views/pairing.html', controller: 'paircontroller' }) .when('/pairs', { templateurl: 'views/pairs.html', controller: 'pairlistcontroller' }); $locationprovider.html5mode(true); } ]);
the route have defined in express server follows...
app.get('/', function(req, res) { var html = fs.readfilesync('public/views/index.html', 'utf8'); res.send(html); });
with other routing functionality living in index file.
you have route requests (expect static ones) index.html:
app.use("/js", express.static(__dirname + "/public/js")); ... app.all('/*', function(req, res) { var html = fs.readfilesync('public/views/index.html', 'utf8'); res.send(html); });
javascript angularjs angularjs-routing
Comments
Post a Comment