私はWes-Bosチュートリアルを行い、フォームがStorePickerから送信された後にApp.jsコンポーネントにリダイレクトする別の方法について考えています。フォームonSubmitの後に新しいコンポーネントにリダイレクトするにはどうすればよいですか?
マイStorePickerコンポーネント:
class StorePicker extends React.Component {
goToStore(event) {
event.preventDefault();
const storeId = this.storeInput.value;
return <Redirect to={`/store/${storeId}`} />;
}
render() {
return (
<Grid textAlign='center' columns={2}>
<Grid.Row>
<Grid.Column><br/>
<Segment>
<Form onSubmit={(e) => this.goToStore(e)} >
<Form.Field >
<h1>Store Name</h1>
<input type="text" required
placeholder="Store Name"
ref={(input) => {this.storeInput = input}}
defaultValue={getFunName()} />
</Form.Field>
<Button fluid type='submit'>Visit Store -></Button>
</Form>
</Segment>
</Grid.Column>
</Grid.Row>
</Grid>
)
}
}
私はを通して見て、ルータのマニュアルを参照して反応し、それが<Redirect />
が動作していないようだと遊んしようとしています。どのようにこのリダイレクトを管理するためのアドバイス?ありがとう
'storeId'パラメータを使用して、選択したストア(おそらく' 'コンポーネント)をレンダリングするコードを表示できますか? –
Jaxx
私は100%確信していませんが、私の 'const storeId = this.storeInput.value;'は 'goToStore();'で定義されています – karolis2017
いいえ、私は '/ store /:storeId'が明らかに 'storeId'パラメータを利用するところがあります。 – Jaxx