javascript - Client Side Routhing with Angular on Node.js & Express -


i'm using node & express on server side, , angular on client side.

but can't implement angular client-side routing. angular router looks this:

app.config(['$routeprovider', function($routeprovider) { $routeprovider.     when('/blogs', {         templateurl: 'partials/blogs',         controller: 'blogcontroller'     }).     when('/news', {         templateurl: 'partials/news',         controller: 'newscontroller'     }).     otherwise({redirectto: '/'}); }]); 

this server routes:

app.use('/',routes.index); app.use('/partials/:filename',routes.partials); 

and index.js:

exports.partials = function(req, res){ var filename = req.params.filename; if(!filename) return; res.render("partials/" + filename ); };  exports.index = function(req, res){ res.render('index'); }; 

but instead of presenting partials, index page every url

what doing wrong?

you have create route this:

router.get('*', function(req, res){     res.render('layout'); }); 

in layout.jade can initialize routes:

    script(src='https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js')     script(src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular-route.js')     script(src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js')     script(src='/javascripts/app.js') 

app.js:

var app = angular.module('app', ["ngroute"]);  app.config(['$routeprovider', function($routeprovider){     $routeprovider.         when('/', {           template: 'ok'         }) }]); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -