router changes
This commit is contained in:
18
src/router/Link.tsx
Normal file
18
src/router/Link.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import React, {PropsWithChildren} from "react";
|
||||
import {useRouter} from "./RouterContext";
|
||||
|
||||
export function Link(props: {className: string, href: string, replace?: boolean } & PropsWithChildren) {
|
||||
const {children, className, href, replace} = props;
|
||||
const router = useRouter();
|
||||
|
||||
function onClick(event: React.MouseEvent) {
|
||||
event.preventDefault();
|
||||
if(replace) {
|
||||
router.replacePage(props.href);
|
||||
} else {
|
||||
router.pushPage(props.href);
|
||||
}
|
||||
}
|
||||
|
||||
return <a onClick={onClick} href={href} className={className}>{children}</a>
|
||||
}
|
||||
Reference in New Issue
Block a user