Appearance
Express response.redirect
TIP
使用可选的状态码跳转到url 状态码status默认为302 "Found"
Express
res.redirect([status], url)
Express
res.redirect('/foo/bar')
res.redirect('http://example.com')
res.redirect(301, 'http://example.com')
res.redirect('../login')
重定向可以是用于重定向到不同站点的完全限定 URL:
Express
res.redirect('http://google.com')
第二种是相对根域路径跳转,比如你现在在http://example.com/admin/post/new , 下面的的代码跳转到 /admin 将会把你带到http://example.com/admin:
Express
res.redirect('/admin');
这是一种相对于应用程序挂载点的跳转。 比如把一个blog程序挂在 /blog, 事实上它无法知道它被挂载,所以当你使用跳转 /admin/post/new时,将到跳到http://example.com/admin/post/new, 下面的相对于挂载点的跳转会把你带到http://example.com/blog/admin/post/new:
Express
res.redirect('admin/post/new');
路径名.跳转同样也是支持的。 比如你在http://example.com/admin/post/new, 下面的跳转会把你带到http//example.com/admin/post:
Express
res.redirect('..');
back 重定向将请求重定向回 referer,当引用者丢失时默认为 /。
Express
res.redirect('back')