0

I would like to have static routes in my application while saving ability to read them somewhere.

For example:

-/Pages
--index.js
--/Account
---Settings.js
---[AccountPages].js

Somewhere in my codebase:

import { useRouter } from 'next/router'
const {AccountPages} = router.query

Problem is that AccountPages will return some value for any page but account/settings

Is it possible to read AccountPages for route that was matched in to static page?

juliomalves
  • 42,130
  • 20
  • 150
  • 146
Peersky
  • 115
  • 7
  • What do you mean by "route that was matched in to static page"? You should be able to access `router.query` on any page you want. – juliomalves Jun 05 '21 at 15:07
  • if my route is /account/settings then calling router.query somewhere in the code will return empty object, while calling it from /account/dynamic_route router.query will return {"accountsPages"} – Peersky Jun 06 '21 at 06:44
  • You get an empty object in `/account/settings` because there are no query params on that path. If you just want to access the path you can use `router.asPath` instead. – juliomalves Jun 06 '21 at 10:53

0 Answers0