react-code-dataset / next.js /packages /next /src /client /components /router-reducer /should-hard-navigate.ts
Download next.js/packages/next/src/client/components/router-reducer/should-hard-navigate.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/client/components/router-reducer/should-hard-navigate.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/client/components/router-reducer/should-hard-navigate.ts
-
curl -L -o should-hard-navigate.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/client/components/router-reducer/should-hard-navigate.ts
1.23 kB
| import type { | |
| FlightRouterState, | |
| FlightDataPath, | |
| Segment, | |
| } from '../../../server/app-render/types' | |
| import { getNextFlightSegmentPath } from '../../flight-data-helpers' | |
| import { matchSegment } from '../match-segments' | |
| // TODO-APP: flightSegmentPath will be empty in case of static response, needs to be handled. | |
| export function shouldHardNavigate( | |
| flightSegmentPath: FlightDataPath, | |
| flightRouterState: FlightRouterState | |
| ): boolean { | |
| const [segment, parallelRoutes] = flightRouterState | |
| // TODO-APP: Check if `as` can be replaced. | |
| const [currentSegment, parallelRouteKey] = flightSegmentPath as [ | |
| Segment, | |
| string, | |
| ] | |
| // Check if current segment matches the existing segment. | |
| if (!matchSegment(currentSegment, segment)) { | |
| // If dynamic parameter in tree doesn't match up with segment path a hard navigation is triggered. | |
| if (Array.isArray(currentSegment)) { | |
| return true | |
| } | |
| // If the existing segment did not match soft navigation is triggered. | |
| return false | |
| } | |
| const lastSegment = flightSegmentPath.length <= 2 | |
| if (lastSegment) { | |
| return false | |
| } | |
| return shouldHardNavigate( | |
| getNextFlightSegmentPath(flightSegmentPath), | |
| parallelRoutes[parallelRouteKey] | |
| ) | |
| } | |