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

Route props #1708

Closed
christiannwamba opened this issue Apr 13, 2017 · 2 comments
Closed

Route props #1708

christiannwamba opened this issue Apr 13, 2017 · 2 comments

Comments

@christiannwamba
Copy link
Contributor

christiannwamba commented Apr 13, 2017

React router which I'm used to, passes route information via props to contained components.

I was hoping to access route payload information via props in Next but it turns out props is an empty object by default.

Is there a way to get information about the current page route like location, param, etc?

@kandros
Copy link
Contributor

kandros commented Apr 13, 2017

Router is a singleton, so you can import from next/router it and get his properties(which is pretty much what react router does, it exposes history package as a singleton)

https://github.com/zeit/next.js/blob/af1afa472be7e8ab15711c84545a92c2a07d223b/lib/router/index.js#L60

at mysite.com?name=jaga

import Router from 'next/router'

Router.pathname // '/'
Router.query // {name: "jaga"}
Router.route // '/'

@christiannwamba
Copy link
Contributor Author

Great. Thank you @kandros

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 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

2 participants