Skip to content

Commit

Permalink
fix: Jan review 4
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatkashyap committed Feb 10, 2025
1 parent 57d3d22 commit ecbf7e3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
7 changes: 6 additions & 1 deletion packages/toolpad-core/src/nextjs/NextAppProviderApp.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as React from 'react';
import Link from 'next/link';
import NextLink from 'next/link';
import { usePathname, useSearchParams, useRouter } from 'next/navigation';
import { LinkProps } from '../shared/Link';
import { AppProvider } from '../AppProvider';
import type { AppProviderProps, Navigate, Router } from '../AppProvider';

const Link = React.forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
const { href, history, ...rest } = props;
return <NextLink ref={ref} href={href} replace={history === 'replace'} {...rest} />;
});
/**
* @ignore - internal component.
*/
Expand Down
8 changes: 7 additions & 1 deletion packages/toolpad-core/src/nextjs/NextAppProviderPages.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import * as React from 'react';
import Link from 'next/link';
import NextLink from 'next/link';
import { asArray } from '@toolpad/utils/collections';
import { useRouter } from 'next/router';
import { LinkProps } from '../shared/Link';
import { AppProvider } from '../AppProvider';
import type { AppProviderProps, Navigate, Router } from '../AppProvider';

const Link = React.forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
const { href, history, ...rest } = props;
return <NextLink ref={ref} href={href} replace={history === 'replace'} {...rest} />;
});

/**
* @ignore - internal component.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { AppProvider, type AppProviderProps, Navigate, Router } from '../AppProv
import { LinkProps } from '../shared/Link';

const Link = React.forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
const { href, ...rest } = props;
return <ReactRouterLink ref={ref} to={href} {...rest} />;
const { href, history, ...rest } = props;
return <ReactRouterLink ref={ref} to={href} replace={history === 'replace'} {...rest} />;
});

function ReactRouterAppProvider(props: AppProviderProps) {
Expand Down
16 changes: 7 additions & 9 deletions packages/toolpad-core/src/shared/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import { RouterContext } from './context';
* @ignore - internal component.
*/

export interface DefaultLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
/*
* "replace" will replace the history stack with the URL being navigated to
* "push" will push the URL being navigated to as a new entry onto the history stack
* "auto" is the default and the mimics the "push" behaviour
*/
history?: 'auto' | 'push' | 'replace';
href: string;
}

export const DefaultLink = React.forwardRef(function Link(
props: DefaultLinkProps,
props: LinkProps,
ref: React.ForwardedRef<HTMLAnchorElement>,
) {
const { children, href, onClick, history, ...rest } = props;
Expand All @@ -36,13 +41,6 @@ export const DefaultLink = React.forwardRef(function Link(
);
});

export interface LinkProps {
href: string;
children: React.ReactNode;
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
style?: React.CSSProperties;
}

export const Link = React.forwardRef(function Link(
props: LinkProps,
ref: React.ForwardedRef<HTMLAnchorElement>,
Expand Down

0 comments on commit ecbf7e3

Please sign in to comment.