title: How to use "useRouter()" from next.js in a class component?
body: <p>I was trying to get the queries from my url pattern like <code>localhost:3000/post?loc=100</code> by using <code>useRouter()</code> from "next/router" and fetching some data using that id from my server. It worked when I used it in a Stateless Functional Component.</p>
  
  <p>But the page showing "Invalid hook call" then. I tried calling <code>getInitalProps()</code> of a Stateless Functional Component, but it didn't work there either and showed the same error.
  Is there any rule to use this method?</p>
  
  <p>I was developing a front-end using React Library and Next.js Framework.</p>
  
  <pre class="lang-js prettyprint-override"><code>constructor(props) {
    this.state = {
      loc: useRouter().query.loc,
      loaded: false
    };
  }
  </code></pre>