-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathgoBackButton.tsx
43 lines (38 loc) · 1.16 KB
/
goBackButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import * as React from 'react';
import { Button } from 'antd';
import { browserHistory, hashHistory } from 'react-router';
import { GoBackButtonProps } from './index';
import useLocale from '../locale/useLocale';
class GoBackButton extends React.Component<GoBackButtonProps, any> {
go = () => {
const { url, history, autoClose } = this.props;
if (url) {
if (history) {
browserHistory.push(url);
} else {
hashHistory.push(url);
}
} else {
if (window.history?.length == 1) {
if (autoClose) {
window.close();
}
} else {
hashHistory.go(-1);
}
}
};
render() {
const { title, locale } = this.props;
return (
<Button {...this.props} onClick={this.go}>
{title || locale.back}
</Button>
);
}
}
const GoBackButtonWrapper = (props: Omit<GoBackButtonProps, 'locale'>) => {
const locale = useLocale('GoBack');
return <GoBackButton {...props} locale={locale} />;
};
export default GoBackButtonWrapper;