Skip to content
codemod transformations to help upgrade Next.js codebases
Branch: master
Clone or download
Latest commit 83ab86d Jun 22, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
transforms Ignore nested arrow functions (#8) Jun 22, 2018
.babelrc Add codemod and tests Jun 11, 2018
.eslintignore Add eslint configuration Jun 22, 2018
package.json 1.0.1 Jun 22, 2018
yarn.lock Add eslint configuration Jun 22, 2018

Next.js codemod

Codemod transformations to help upgrade Next.js codebases

How to use


Install jscodeshift:

npm install -g jscodeshift



Tranforms the deprecated automatically injected url property on top level pages to using withRouter and the router property it injects. Read more here:

For example:

// From
import React from 'react'
export default class extends React.Component {
  render() {
    const {pathname} = this.props.url
    return <div>Current pathname: {pathname}</div>
// To
import React from 'react'
import {withRouter} from 'next/router'
export default withRouter(class extends React.Component {
  render() {
    const {pathname} = this.props.router
    return <div>Current pathname: {pathname}</div>

This is just one case. All the cases that are transformed (and tested) can be found in the __testfixtures__ directory.


Go to your project

cd path-to-your-project

Download the codemod:

curl -L | tar -xz --strip=2 next-codemod-master/transforms/url-to-withrouter.js

Run the transformation:

jscodeshift -t ./url-to-withrouter.js pages/**/*.js

After the transformation is done the url-to-withrouter.js file in the root of your project can be removed.


You can’t perform that action at this time.