fix: normalize path for search result

This commit is contained in:
Justineo 2021-10-22 17:04:26 +08:00
parent b8432a870e
commit 2a59d493a5
No known key found for this signature in database
GPG Key ID: B73F0979CF18A0EA
2 changed files with 13 additions and 3 deletions

View File

@ -27,6 +27,15 @@ function isSpecialClick (event) {
event.shiftKey event.shiftKey
) )
} }
function normalizeURL (url) {
if (url.endsWith('/')) {
return url.slice(0, -1)
}
return url.replace(/\/([#?])/, '$1')
}
export default { export default {
name: 'one-search', name: 'one-search',
components: { components: {
@ -90,10 +99,11 @@ export default {
}) })
}, },
hitComponent: ({ hit, children }) => { hitComponent: ({ hit, children }) => {
const url = normalizeURL(hit.url)
return createElement( return createElement(
'a', 'a',
{ {
href: hit.url, href: url,
onClick: event => { onClick: event => {
if (isSpecialClick(event)) { if (isSpecialClick(event)) {
return return
@ -112,7 +122,7 @@ export default {
if (this.$router.history.current.path !== hitPathname) { if (this.$router.history.current.path !== hitPathname) {
event.preventDefault() event.preventDefault()
} }
this.$router.push(hit.url) this.$router.push(url)
}, },
children children
} }

View File

@ -1,7 +1,7 @@
# InputGroup <small>输入组件组</small> # InputGroup <small>输入组件组</small>
:::tip :::tip
`Input` 组件需要内联 [`Input`](./input)、[`NumberInput`](./number-input)、[`Autocomplete`](autocomplete)、[`SearchBox`](./search-box)、[`Select`](./select)、[DatePicker](./date-picker)、[TimePicker](./time-picker)、[`Dropdown`](./dropdown)、[`Button`](./button)、[`ButtonGroup`](./button-group)、[`Label`](./label)、[`Span`](./span) 等组件配合使用。 `Input` 组件需要内联 [`Input`](./input)、[`NumberInput`](./number-input)、[`Autocomplete`](autocomplete)、[`SearchBox`](./search-box)、[`Select`](./select)、[`DatePicker`](./date-picker)、[`TimePicker`](./time-picker)、[`Dropdown`](./dropdown)、[`Button`](./button)、[`ButtonGroup`](./button-group)、[`Label`](./label)、[`Span`](./span) 等组件配合使用。
::: :::
## 示例 ## 示例