├── History.md ├── Readme.md ├── index.js └── package.json /History.md: -------------------------------------------------------------------------------- 1 | 2 | 1.0.1 / 2017-01-17 3 | ================== 4 | 5 | * export module 6 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Redirect 2 | 3 | Redirect for [next.js](https://github.com/zeit/next.js). Works on both the client and server 4 | 5 | ## Usage 6 | 7 | ``` 8 | static async getInitialProps (ctx) { 9 | const [ err, course ] = await poss(loadCourse(ctx.query.course)) 10 | if (err) return redirect(ctx, '/') 11 | return course 12 | } 13 | ``` 14 | 15 | ## Installation 16 | 17 | ``` 18 | npm install next-redirect 19 | ``` 20 | 21 | ## License 22 | 23 | MIT -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Export `redirect` 3 | */ 4 | 5 | module.exports = redirect 6 | 7 | /** 8 | * Redirect 9 | */ 10 | 11 | function redirect (ctx, path) { 12 | if (ctx.res) { 13 | ctx.res.writeHead(302, { Location: path }) 14 | ctx.res.end() 15 | } else { 16 | document.location.pathname = path 17 | } 18 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "next-redirect", 3 | "version": "1.0.1", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | --------------------------------------------------------------------------------