diff --git a/components/OneSearch.vue b/components/OneSearch.vue index 525f3bb..5eac308 100644 --- a/components/OneSearch.vue +++ b/components/OneSearch.vue @@ -27,6 +27,15 @@ function isSpecialClick (event) { event.shiftKey ) } + +function normalizeURL (url) { + if (url.endsWith('/')) { + return url.slice(0, -1) + } + + return url.replace(/\/([#?])/, '$1') +} + export default { name: 'one-search', components: { @@ -90,10 +99,11 @@ export default { }) }, hitComponent: ({ hit, children }) => { + const url = normalizeURL(hit.url) return createElement( 'a', { - href: hit.url, + href: url, onClick: event => { if (isSpecialClick(event)) { return @@ -112,7 +122,7 @@ export default { if (this.$router.history.current.path !== hitPathname) { event.preventDefault() } - this.$router.push(hit.url) + this.$router.push(url) }, children } diff --git a/one/docs/components/input-group.md b/one/docs/components/input-group.md index 7cdad25..d9a1bb5 100644 --- a/one/docs/components/input-group.md +++ b/one/docs/components/input-group.md @@ -1,7 +1,7 @@ # InputGroup 输入组件组 :::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) 等组件配合使用。 ::: ## 示例