Skip to content
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

Add a nice way to get the router API inside a component #2032

Closed
arunoda opened this issue May 21, 2017 · 17 comments
Closed

Add a nice way to get the router API inside a component #2032

arunoda opened this issue May 21, 2017 · 17 comments
Assignees

Comments

@arunoda
Copy link
Contributor

arunoda commented May 21, 2017

We need an HOC API like this:

import { withRouter } from 'next/router'

const Comp = (props) => ({ props.router.asPath })
export default withRouter()(Comp)
@nwshane
Copy link

nwshane commented May 21, 2017

@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?

@arunoda
Copy link
Contributor Author

arunoda commented May 21, 2017

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.

@sbekrin
Copy link

sbekrin commented May 21, 2017

@nwshane @arunoda sorry for breaking in, but I've been doing same thing with monkey-patching (locally). Just sharing whatever I have.

@nwshane
Copy link

nwshane commented May 23, 2017

@sergeybekrin Thanks, these files are helpful.

@arunoda I've gotten this working already, just a few questions...

  1. Should I make a branch off of master containing this change? Or off of v3-beta?
  2. Do you think it would be good to add this into the using-router example?
  3. I'm trying npm run lint but it causes npm to throw an error. Not really sure what to do about that. Any suggestions?

@arunoda
Copy link
Contributor Author

arunoda commented May 23, 2017

@nwshane

  • Use the master
  • Yes. Use the using-router. But better to change the example that it can be used in the server. Better example would be the showing the active state of a link.
  • run npm run lint -- --fix. If still persists, fix the issue

@nwshane
Copy link

nwshane commented May 24, 2017

@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.

@arunoda
Copy link
Contributor Author

arunoda commented May 26, 2017

@nwshane shall we discuss this on the PR. Could you tell me about the issue there?

@ayazhussein
Copy link

Any updates? @arunoda @nwshane Thank you in advance!! :D

@arunoda
Copy link
Contributor Author

arunoda commented Jun 13, 2017

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.

@chhuang
Copy link

chhuang commented Jun 13, 2017

Will this feature be included in 3.0?

@ghost
Copy link

ghost commented Jun 17, 2017

Waiting

@i8ramin
Copy link
Contributor

i8ramin commented Jul 16, 2017

Any updates on this? been dying for a way to add an "active" class to my links

@timneutkens
Copy link
Member

@i8ramin it's going to be merged after v3 lands.

@HaNdTriX
Copy link
Contributor

@i8ramin this is the current progress: #2352

@alexedev
Copy link

alexedev commented Aug 18, 2017

@timneutkens should it be merged already?

@fritz-c
Copy link

fritz-c commented Aug 31, 2017

This is available in 3.2.0 now.

@timneutkens
Copy link
Member

@fritz-c thanks, closed 👌

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants