zl2003cn
zl2003cn

Reputation: 485

How to refer state in link on react-router

I use a router like this:

render((
  <Router history={browserHistory}>
    <Route path="/" component={App}>
      <IndexRoute component={Home}/>
      <Route path="/detail/:blogId" component={DetailView}/>
    </Route>
  </Router>
), document.getElementById('app'))

and in blog.js I use Link

<Link to={{ pathname: "/detail", query: { blogId: this.props.id } }}>Detail</Link>

but it didn't work, how to replace the :blogId part with state or props?

Upvotes: 4

Views: 660

Answers (2)

Mark Anderson
Mark Anderson

Reputation: 663

:blogId is a param, not a query.

You can simply set your param in the link tag like this:

<Link to={'/detail/' + this.props.id}>Detail</Link>

Upvotes: 1

Dennis Nerush
Dennis Nerush

Reputation: 5663

Just write Var link= "detail/" + this.props.id;

Detail

Upvotes: 0

Related Questions