Link params not working
See original GitHub issueI have tried the following combos:
With href: works, but reloads the whole page and says 404 for 3 seconds.
<Link href={'/blog/'+post.id}><a>{post.title}</a></Link>
With params: The href looks good, but clicking the link throw an error (see below).
<Link route='blog/entry' params={{id: post.id}}><a>{post.title}</a></Link>
With to: The href looks good, but clicking the link throw an error (see below).
<Link to={'/blog/'+post.id}><a>{post.title}</a></Link>
Error:
TypeError: Cannot read property 'id' of undefined
at Post (http://localhost:3000/_next/1509617163196/page/blog/entry:43023:55)
at mountIndeterminateComponent (http://localhost:3000/_next/1509617163196/commons.js:10406:15)
at beginWork (http://localhost:3000/_next/1509617163196/commons.js:10607:16)
at performUnitOfWork (http://localhost:3000/_next/1509617163196/commons.js:12579:16)
at workLoop (http://localhost:3000/_next/1509617163196/commons.js:12688:28)
at HTMLUnknownElement.callCallback (http://localhost:3000/_next/1509617163196/commons.js:1305:14)
at Object.invokeGuardedCallbackDev (http://localhost:3000/_next/1509617163196/commons.js:1344:16)
at invokeGuardedCallback (http://localhost:3000/_next/1509617163196/commons.js:1201:27)
at performWork (http://localhost:3000/_next/1509617163196/commons.js:12806:7)
at scheduleUpdateImpl (http://localhost:3000/_next/1509617163196/commons.js:13191:19)
The Link is in components/PostList.js.
Src:
- Branch with href: https://github.com/benevolenttech/apollo-cms
- Branch with params: https://github.com/benevolenttech/apollo-cms/tree/link-params-test2
- Branch with to: https://github.com/benevolenttech/apollo-cms/tree/link-params-test3
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
React router not working with params - Stack Overflow
it works for me too! in my case it works because if the base url is not set, it will try to load...
Read more >The Complete Guide to URL parameters with React Router
URL parameters are parameters whose values are set dynamically in a page's URL. In this post you'll learn how to use URL parameters...
Read more >link to dynamic route with query params not working client-side
I think it's not possible to create a Link for dynamic route with query params in a way which would work both server-side...
Read more >How to Access URL Parameters Using React Router 6
2️⃣ How to Retrieve URL Parameters Using Class Components. Class Components do not have access to Hooks so they cannot use useParams() ...
Read more >URL Parameters not working - WordPress.org
Hello there,. After opening the lists I would like to show ads based on utm parameters. The parameter I have tried with is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FWIW, submitted a PR for null param values (not sure this solves the OPs issue, but is tangentially related)
Hi @bdombro please try to move asynchronous data fetching into
getInitialProps
, so Next.js will wait with the rendering until all required data (likepost
object) is available. That should be here in your code: https://github.com/benevolenttech/apollo-cms/blob/link-params-test2b/pages/blog/entry.js#L12