mirror of
https://github.com/primer/css.git
synced 2024-11-27 17:52:45 +03:00
docs: do one thing well in redirectTrailingSlash()
This commit is contained in:
parent
0988e6ecdf
commit
1f8929550f
@ -1,5 +1,4 @@
|
||||
import Router from 'next/router'
|
||||
import Error from 'next/error'
|
||||
|
||||
/**
|
||||
* Export this as your default from a page, and it'll redirect both server-
|
||||
@ -31,14 +30,11 @@ export default function redirect(uri, status = 303) {
|
||||
}
|
||||
|
||||
export function redirectTrailingSlash(context, status = 301) {
|
||||
const {req, res} = context
|
||||
if (req.url.endsWith('/')) {
|
||||
const {url} = req
|
||||
const {req: {url}, res} = context
|
||||
if (url.endsWith('/')) {
|
||||
const withoutSlash = url.substr(0, url.length - 1)
|
||||
res.writeHead(status, {Location: withoutSlash})
|
||||
res.end()
|
||||
return true
|
||||
} else {
|
||||
return Error.getInitialProps(context)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user