Next.js: 'url' property is deprecated - question

Created on 6 May 2018  路  13Comments  路  Source: vercel/next.js

I am using withRouter HoC as described in this snippet, however, I am still getting the error:

 utils.js:26 Warning: the 'url' property is deprecated. https://err.sh/next.js/url-deprecated

  • [x ] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior



Code executes without the deprecation warning.

Current Behavior



The error mentioned above appears.

Steps to Reproduce (for bugs)


  1. Import withRouter to your component
  2. Refer any field from this.props.router
  3. Export your component wrapped in withRouter HoC
  4. When component is rendered, the deprecation error appears in console

Context



I am implementing Navigation component that is aware of the current route (to highlight the NavItem).

Your Environment


| Tech | Version |
|-------|-------|
| next | 6.0.0 |
| node | 9.11.1 |
| OS | OSX 10.13.4 |
| browser | Chrome Version 66.0.3359.139 |

Most helpful comment

I've removed the suggestions in this thread saying you should create a custom _app.js that passes in the url property globally, as the reason we removed it is to be more explicit and not pass in url as a property, but instead you can inject the router using withRouter() as per the deprecation. We will provide a codemod soon to update url in pages to the withRouter() implementation automatically.

All 13 comments

I do not have a custom App component and I still get the warning. I do have a custom _document with the contents described here https://github.com/zeit/next.js#custom-document
Any ideas how to get rid of that warning?

I'd like to investigate this further.

I think this should be told in the readme because now it just states that "Each top-level component receives a url property..."

Maybe there should be a note of the special case when using custom App component?

continously focus on this issue

One of my child components triggers the warning with JSON.stringify( this.props ).

I'm using a pretty standard configuration (no custom App, no attempt to ever reference url) and I get this warning. I don't think we should be forced into using a custom _app.js just to get rid of this.

@remy mentioned it's possible that React devtools triggers the url property read that causes the warning to show

@timneutkens Yep, that appears to be the issue in my setup. Should we update the error docs to reflect this?

I've removed the suggestions in this thread saying you should create a custom _app.js that passes in the url property globally, as the reason we removed it is to be more explicit and not pass in url as a property, but instead you can inject the router using withRouter() as per the deprecation. We will provide a codemod soon to update url in pages to the withRouter() implementation automatically.

I just open sourced the codemod we used to upgrade 35K+ lines of code from url to withRouter:

https://github.com/zeit/next-codemod#url-to-withrouter

@scaasic regarding documenting the React devtools property read, sure feel free to send a pull request. We always welcome documentation improvements 馃槍

After re-visiting this issue it seems like there's nothing wrong. Only React Devtools making it log out the warning, unfortunately, we can't get around that. @scaasic has created a pull request that adds a message saying react devtools can cause the warning to show up.

After re-visiting this issue it seems like there's nothing wrong. Only React Devtools making it log out the warning, unfortunately, we can't get around that. @scaasic has created a pull request that adds a message saying react devtools can cause the warning to show up.

after tried next from /learn getting started I encountered this problem and when I disable/ turn off devtools no warning message. Is this still no update to fix this warning?

I was getting this warning message when I accessed the property query in this.props.url, in some page with query param url, like post?id=22, even by console when I printed this.props.

I got fix it using withRouter from next/router and accessing query from this.props.router.

import { withRouter } from "next/router";

class Single extends Component {
  componentDidMount = () => {
    const { router: { query: { id } }} = this.props;
    console.log(id);
  };
}

export default withRouter(Single);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

acanimal picture acanimal  路  74Comments

matthewmueller picture matthewmueller  路  102Comments

nickredmark picture nickredmark  路  60Comments

timneutkens picture timneutkens  路  72Comments

iamstarkov picture iamstarkov  路  119Comments