简体   繁体   中英

Why is html route not working in express.js?

So it's a pretty trivial question... I have a get request in my client code.

function tosurvey(){$.get( "/survey", d=>d?console.log("Redirected"):false);}

And a listener on the back

 router.get('/survey', function(req, res) {
        res.sendFile('survey.html', { root: path.join(__dirname, '../public') });
    });

However, it doesn't work. If you go directly to /survey, it does work, but get request is pointing to /survey too and should be happening onclick as it is binded to click event on the front.

This fixed it.

    let x = window.location.pathname;
    x=x.split("/");
    x.pop();
    x=x.join('/');
   $.get("/", d=>d?(console.log("Redirected"),window.location=x+'/'):false);

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