5

I am using versions

"react": "^0.13.3",
"react-router": "^0.13.3" 

i want to receive the params in which it navigate

1)Navigation done properly

2)what when i try to use this.props.query.id for receiving arguments it show undefined.

2 Answers 2

5

upgrade to react-router v4 and ;

Use this instead:

this.props.location.search

if you have a URL like mysite.com/user/tweets?filter=top&origin=im

Doing:

console.log(this.props.location.search); //yields "?filter=top&origin=im"

Thus to get the value of "filter" or "origin", you need to use a package for parsing query strings because react-router doesn’t come with built-in support for parsing query strings. E.g. using 'query-string' library on NPM you can do:

import queryString from 'query-string';

const UrlQueryStrings = this.props.location.search;
const queryValues = queryString(UrlQueryStrings);

console.log(queryValues.filter); // Gives "top"
console.log(queryValues.origin); // Gives "im"
Sign up to request clarification or add additional context in comments.

3 Comments

But how do you get the value for filter in this case?
@kabuto178 I have included how to get the values of the query parameters.
It should be queryString.parse(...)
2

Use this:

this.props.location.query.id

4 Comments

use console.log('id', this.props.location.query.id) inside render method, and check the result
done 1) this.transitionTo('template', null, {id: 10} );
Mayank Shukla can you plz tell me best way to use session and cookies in react.js
don't have much idea check this, may be help you: reddit.com/r/reactjs/comments/4dw782/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.