MCPcopy
hub / github.com/vercel/next.js / applyDestination

Function applyDestination

packages/next-routing/src/destination.ts:51–72  ·  view source on GitHub ↗
(currentUrl: URL, destination: string)

Source from the content-addressed store, hash-verified

49 * if it's external
50 */
51export function applyDestination(currentUrl: URL, destination: string): URL {
52 if (isExternalDestination(destination)) {
53 return new URL(destination)
54 }
55
56 // Create a new URL with the updated pathname
57 const newUrl = new URL(currentUrl.toString())
58
59 // Handle destinations with query strings
60 const [pathname, search] = destination.split('?')
61 newUrl.pathname = pathname
62
63 if (search) {
64 // Merge query parameters
65 const newParams = new URLSearchParams(search)
66 for (const [key, value] of newParams.entries()) {
67 newUrl.searchParams.set(key, value)
68 }
69 }
70
71 return newUrl
72}
73
74/**
75 * Checks if a status code is a redirect status code

Callers 2

processRoutesFunction · 0.90
resolveRoutesFunction · 0.90

Calls 5

isExternalDestinationFunction · 0.85
splitMethod · 0.80
setMethod · 0.65
toStringMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected