2018-04-12 08:33:22 +00:00
# Url is deprecated
#### Why This Error Occurred
2018-06-22 12:21:28 +00:00
In versions prior to 6.x the `url` property got magically injected into every `Page` component (every page inside the `pages` directory).
The reason this is going away is that we want to make things very predictable and explicit. Having a magical url property coming out of nowhere doesn't aid that goal.
2018-04-12 08:33:22 +00:00
#### Possible Ways to Fix It
2018-06-22 12:21:28 +00:00
https://github.com/zeit/next-codemod#url-to-withrouter
Since Next 5 we provide a way to explicitly inject the Next.js router object into pages and all their decending components.
The `router` property that is injected will hold the same values as `url` , like `pathname` , `asPath` , and `query` .
Here's an example of using `withRouter` :
2018-04-12 08:33:22 +00:00
```js
import { withRouter } from 'next/router'
class Page extends React.Component {
render() {
const {router} = this.props
console.log(router)
return < div > {router.pathname}< / div >
}
}
export default withRouter(Page)
```
2018-06-22 12:21:28 +00:00
We provide a codemod (a code to code transformation) to automatically change the `url` property usages to `withRouter` .
You can find this codemod and instructions on how to run it here: https://github.com/zeit/next-codemod#url-to-withrouter