redirect in express code example
Example 1: javascript redirect
window.location.href = "http://mywebsite.com/home.html";
Example 2: express redirect
app.get('/', (req, res) => {
res.redirect('/foo/bar');
});
Example 3: express redirect
res.redirect('https://google.com')
Example 4: express redirect
res.redirect('/foo/bar')
res.redirect('http://example.com')
res.redirect(301, 'http://example.com')
res.redirect('../login')
Example 5: express url redirect
const app = require('express')();
app.get('/from', (req, res) => {
res.redirect('/to');
});
app.get('/to', (req, res) => res.send('Hello, World!'));
Example 6: express js redirect to url
app.get('/', function (req, res) {
res.send('GET request to the homepage')
})
app.post('/', function (req, res) {
res.send('POST request to the homepage')
})