I'm following the React for Beginner tutorial by using the React Router V4.However I can't get my params in my component.Here's part of my code.
const Root = () => {
return (
<BrowserRouter>
<div>
<Switch>
<Route exact path='/' component={StorePicker} />
<Route Path='store/:storeId' component={App} />
<Route component={NotFound} />
</Switch>
</div>
</BrowserRouter>
)
}
StorePicker component:
class StorePicker extends React.Component {
render() {
return (
<form className="store-selector" onSubmit={(e) => this.goToStore(e)}>
<h2>Please Enter A Store</h2>
<input type="text" ref={(input) => { this.storeInput= input; }} defaultValue={getFunName()} placeholder="Store Name" required/>
<button type="submit">Visit Store</button>
</form>
)
}
goToStore(event) {
event.preventDefault()
const storeInput = this.storeInput.value
console.log(storeInput)
this.props.history.push(`store/${storeInput}`)
}
}
And in my App component I can't get the storeId.
//storeId is undefine
this.props.match.params.storeId
What's wrong with my code?