10 examples of 'express redirect to url' in JavaScript

Every line of 'express redirect to url' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
17function redirect (req, res) {
18 const path = req.params.path || ''
19 const url = config.settingsUrl + (path ? '/' + path : '')
20 res.redirect(url)
21}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

6redirect(req, res) {
7 res.redirect("/test/redirectTo");
8}
78redirect(url = '/', options = {}) {
79 this._response.redirect(url, options.httpStatus || 302);
80}
18router.get(/^\/signup\/$/, function redirect(req, res) {
19 /*jslint unparam:true*/
20 res.set({'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S});
21 res.redirect(301, subdir + '/ghost/signup/');
22});
310function redirect(url) {
311 var
312 hash_pos = url.indexOf('#'),
313 query_pos = url.indexOf('?'),
314 hash = '';
315 if (hash_pos >=0 ) {
316 hash = url.substring(hash_pos);
317 url = url.substring(0, hash_pos);
318 }
319 url = url + (query_pos >= 0 ? '&' : '?') + 't=' + new Date().getTime() + hash;
320 console.log('redirect to: ' + url);
321 location.assign(url);
322}
168function redirect(url){
169 console.log('redirect')
170 window.location.href = url
171 }
37redirect(url, statusCode = 302) {
38 if(this._redirectInfo) {
39 throw new Error(`Already redirected to: ${this._redirectInfo.url}`);
40 }
41
42 this._redirectInfo = {url, statusCode};
43}
30private redirect() {
31 this.$location.path('/auth/login');
32 this.$location.search({ uri: '/' });
33 this.$location.replace();
34}
24function redirect(res, location) {
25 res.end(getHeader(302, 'Location: ' + location + '\r\n'));
26}
37function redirect(redirectUrl) {
38 try { window.location.replace(redirectUrl); }
39 catch(e) { window.location = redirectUrl; }
40}

Related snippets