Home > OS >  location.href is not working in script tag in html file. how can i fix it?
location.href is not working in script tag in html file. how can i fix it?

Time:02-01

<script> location.href = "../views/test.html"; </script>

it doesn't work in the Node.js project

main.html and test.html are in the same location

ESPractice/views/main.html ESPractice/views/test.html

what should i do to fix it?

CodePudding user response:

You can use res.redirect('/test'); to redirect with Express.js. There is no location variable in Node.js.

Below is the similar code to your post.

app.get('/html', (req, res) => {
    res.redirect('/test');
})
app.get('/test', (req, res) => {
    res.sendFile(path.join(staticPath, "test.html"));
}
  • Related