fix: broken linkify

fixes #1655
This commit is contained in:
romanhotsiy 2021-07-01 12:34:49 +03:00
parent f944da0e7d
commit 3df72fb99f
No known key found for this signature in database
GPG Key ID: 0BC2221278CCBBB8

View File

@ -39,9 +39,9 @@ const isModifiedEvent = (event) =>
export function Link(props: { to: string; className?: string; children?: any }) { export function Link(props: { to: string; className?: string; children?: any }) {
const store = React.useContext(StoreContext); const store = React.useContext(StoreContext);
const clickHandler = React.useCallback( const clickHandler = React.useCallback(
(event) => { (event: React.MouseEvent<HTMLAnchorElement>) => {
if (!store) return; if (!store) return;
navigate(store.menu.history, event); navigate(store.menu.history, event, props.to);
}, },
[store], [store],
); );
@ -60,14 +60,14 @@ export function Link(props: { to: string; className?: string; children?: any })
); );
} }
function navigate(history: HistoryService, event) { function navigate(history: HistoryService, event: React.MouseEvent<HTMLAnchorElement>, to: string) {
if ( if (
!event.defaultPrevented && // onClick prevented default !event.defaultPrevented && // onClick prevented default
event.button === 0 && // ignore everything but left clicks event.button === 0 && // ignore everything but left clicks
!isModifiedEvent(event) // ignore clicks with modifier keys !isModifiedEvent(event) // ignore clicks with modifier keys
) { ) {
event.preventDefault(); event.preventDefault();
history.replace(this.props.to); history.replace(to);
} }
} }