简体   繁体   中英

How do I handle Page Refresh with Angular.js?

I just followed the setup from http://scotch.io/bar-talk/setting-up-a-mean-stack-single-page-application

This tutorial introduced controllers and services with angular.js for a single-page app..

When I directly visit /pageName, or click the anchor-link for the /pageName route and then press the browser 'Refresh', the page displays:

Error: ENOENT, stat './public/views/index.html'

After reading some answers to similar questions, I changed:

app.get('*', function(req, res) {
    res.sendfile('./public/views/index.html');
});

to:

res.sendfile(__dirname + '/public/views/index.html');

..though now the result is Error: ENOENT, stat '/app/app/public/views/index.html'

well, first of all, your file is in ./public/index.html , and you are searching in ./public/views/index.html , try:

res.sendfile('./public/index.html');

if that doesen't work,try this:

app.get('*', function(req, res) {
     res.sendfile('index.html', { root: './public' });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM