-
Notifications
You must be signed in to change notification settings - Fork 26.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next.js useRouter() query: { amp: undefined } #8051
Comments
Hi! Questions belong on our Spectrum, please open a support request there with a reproduction repository. Also, in your provided code I don't see the need for a custom server, dynamic routes would fulfill your needs: |
Does |
i have the same problem,How did you solve it |
All you need to do to resolve this is useEffect to make sure it runs after router has initialized. For example: const [queryId, setQueryId] = useState(null)
useEffect(()=> {
if(router && router.query) {
setQueryId(router.query.id)
}
}, [router]) |
It seems a bit user-unfriendly that the |
This is the workaround I used: const queryString = require('query-string'); // https://www.npmjs.com/package/query-string
const { filters } = queryString.parse(router.asPath.substring(1)); I noticed that |
There can't be a good reason, it's a bug. The returning of the router object SHOULD block by default, or we should be able to configure it to block until the query attribute has been set. |
Had the same issue with type-in urls. Waiting in useEffect for router.query to be initalized first sovled my problem. |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
I am having issues passing in query objects to
useRouter()
hook. I am attempting to capture URL params and pass it into a page componentpages/post.js
server-side usingkoa.
andkoa-router
.I am using
Koa.js
as my middleware based on next.js example: custom-koa-serverand using Next's documentation: Custom routes (using props from URL)
useRoute() console.log
When attempting to access the
query
object, no matter what, I get{ amp: undefined }
Any help on this will be super helpful! Thank you in advance!
The text was updated successfully, but these errors were encountered: