1
0
mirror of https://github.com/BoostIo/Boostnote synced 2026-01-06 05:29:21 +00:00

fix: fix crash on /searched

Add routing for search word:

- `/searched/:searchword`

Restore the state from the `:searchword` params.
This commit is contained in:
azu
2018-03-25 00:33:57 +09:00
parent 02095ac155
commit 3b0f664a3b
3 changed files with 19 additions and 6 deletions

View File

@@ -28,6 +28,14 @@ class TopBar extends React.Component {
}
componentDidMount () {
const { params } = this.props
const searchWord = params.searchword
if (searchWord !== undefined) {
this.setState({
search: searchWord,
isSearching: true
})
}
ee.on('top:focus-search', this.focusSearchHandler)
ee.on('code:init', this.codeInitHandler)
}
@@ -97,9 +105,10 @@ class TopBar extends React.Component {
this.setState({
isConfirmTranslation: true
})
router.push('/searched')
const keyword = this.refs.searchInput.value
router.push(`/searched/${encodeURIComponent(keyword)}`)
this.setState({
search: this.refs.searchInput.value
search: keyword
})
}
}
@@ -108,7 +117,7 @@ class TopBar extends React.Component {
const { router } = this.context
const keyword = this.refs.searchInput.value
if (this.state.isAlphabet || this.state.isConfirmTranslation) {
router.push('/searched')
router.push(`/searched/${encodeURIComponent(keyword)}`)
} else {
e.preventDefault()
}