title: NextJS: dynamic router.pathname does not show path, but filename - how to get words in path?
body: <p>I'm making this as simple of an example as possible, I can include more code later if it needs more info to be resolved</p>
  <p>I'm using dynamic routes in nextJS. My app pulls results from twitter based on the keywords entered into the dynamic route via API using <code>twitter-v2</code> package</p>
  <p>I'm trying to use the words in the route using <code>router.pathname</code> in order to create some attributes on the page, but it uses the filename instead of the words in the url.</p>
  <p>NextJS version: <code>Next 9.5.3</code></p>
  <p>Render page path: <code>/pages/[keywords].jsx</code></p>
  <p>Example url:</p>
  <pre><code>http://localhost:3000/kpop-heroes
  </code></pre>
  <p>example page function:</p>
  <pre><code>import Router from 'next/router'
  
  export default function Keywords() {
    const router = useRouter();
  
    const KEYWORDS = router.pathname
      .slice(1)
      .split('-')
      .join(' ');
  
    return (
     &lt;div&gt;Twitter reactions to &lt;code&gt;{KEYWORDS}&lt;/code&gt;&lt;/div&gt;
    )
  };
  </code></pre>
  <p>Renders:</p>
  <p><a href="https://i.stack.imgur.com/g9GLC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/g9GLC.png" alt="Pathname renders filename, not words typed in URL" /></a></p>
  <p>Am I misunderstanding this feature? Is it possible to retrieve the words in the url instead of the filename?</p>
  <p>Note:  I've been using <code>window.location.href</code> as a workaround, but my understanding is accessing the window object is less than optimal</p>