We need an HOC API like this:
import { withRouter } from 'next/router'
const Comp = (props) => ({ props.router.asPath })
export default withRouter()(Comp)
@arunoda Not sure if you want my help, but I would be interested in trying to implement this. Want me to give it a go or do you prefer to do it yourself?
I've to delay this for a week. Yeah! Go ahead. I'll fine tune it.
Allow us to edit changes when submitting the PR.
This is the place you need to add the router to the context.
@nwshane @arunoda sorry for breaking in, but I've been doing same thing with monkey-patching (locally). Just sharing whatever I have.
@sergeybekrin Thanks, these files are helpful.
@arunoda I've gotten this working already, just a few questions...
npm run lint
but it causes npm to throw an error. Not really sure what to do about that. Any suggestions?@nwshane
npm run lint -- --fix
. If still persists, fix the issue@arunoda There's the PR. I left the error page so that people know that using 'next/router' directly will break SSR, but I changed the Header to use a CustomLink that is wrapped by withRouter. I took your idea of showing the active state of a link, thanks for that :)
I noticed when implementing this that props.router.asPath
is undefined
on the server. Can that be fixed to pass down the correct asPath
value? Otherwise it still doesn't fix my use case described here, because I need props.router.asPath
on server and client.
@nwshane shall we discuss this on the PR. Could you tell me about the issue there?
Any updates? @arunoda @nwshane Thank you in advance!! :D
Guys, sorry for not taking this yet.
We are currently in feature freeze due to 3.0 release.
Once we did it we'll take this in ASAP.
Will this feature be included in 3.0?
Waiting
Any updates on this? been dying for a way to add an "active" class to my links
@i8ramin it's going to be merged after v3 lands.
@i8ramin this is the current progress: https://github.com/zeit/next.js/pull/2352
@timneutkens should it be merged already?
This is available in 3.2.0 now.
@fritz-c thanks, closed 馃憣
Most helpful comment
@timneutkens should it be merged already?