gamer
gamer

Reputation: 5863

reactjs routes get string on parameter

I have a react router set up like:

const routes =  (
  <Router>

    <Route path={"audio" + "/:audio_url"} component={AudioView} />
    <Route path="*" component={ErrorView} />
  </Router>
)

Here I am passing my audio url like:

'play/3456'

when I pass access url like 'audio/play/3456' it is redirecting me to ErrorView. It should redirect me to AudioView right ?

What might be the issue here ??

Upvotes: 0

Views: 100

Answers (2)

Paul S
Paul S

Reputation: 36787

Params don't span across URL fragments. If both play and 3456 should be params, you should define them separately.

<Route path='audio/:command/:audio_url' component={AudioView} />

Upvotes: 0

StateLess
StateLess

Reputation: 5402

The route

<Route path={"audio" + "/:audio_url"} component={AudioView} />

matches only audio/123

You should include play in the route

<Route path="/audio/play/:id" component={AudioView}> 

Or if you are not sure of the route pattern add *

<Route path="/audio/*" component={AudioView}> 

remember this matches anything after audio/

If possible prefer the first approach.

Upvotes: 2

Related Questions