This is a test using Express to pass data to routes via getInitialProps
.
This code test was created from https://github.com/zeit/next.js/tree/canary/examples/custom-server-express
When using Link
component, you can see that some of the data (testObject
and testArray
- see server.js
) are showing up as undefined when navigating to/from the two sample posts (also using the back/forward browser buttons - see console output). On refresh, they show correct values.
- Open browser at
localhost:3000
- Click
<Link>
nav, see output. Does not showtestObject
andtestArray
unless page is reloaded.
When using the non Link
nav, there is no such issue, testObject
and testArray
are passed correctly.
- Open browser at
localhost:3000
- Click non
<Link>
nav, see output. ShowstestObject
andtestArray
correctly.
Conclusion, do not use <Link>
with custom server implemenation?
Curiously, in Safari (11.1), testObject
fails to be passed getInitialProps
when using the non Link
nav and then using back/forward browser buttons:
- Open safari at
localhost:3000
- click non Link nav, post 1
- click non link nav, post 2
- Now use Safari back/forward button and view results.
Question: what is the proper way to handle routing when using Express. <Link>
? no <Link>
, Router
? There must be some combination that does not result in loss of initial props.