{"record":{"id":"4c0325fb0f6f93c2","repo":"sveltejs/kit","slug":"dev-cannot-use-caller-with-a-url-that-does-n","errorCode":null,"errorMessage":"DEV: Cannot use `${caller}` with a URL that does not resolve to a route within the app. Use `window.location = \"${url}\"` instead | PROD: ${caller}: invalid URL","messagePattern":"DEV: Cannot use `(.+?)` with a URL that does not resolve to a route within the app\\. Use `window\\.location = \"(.+?)\"` instead \\| PROD: (.+?): invalid URL","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/client/client.js","lineNumber":2653,"sourceCode":"/**\n * @param {string | URL} url\n * @param {'goto' | 'pushState' | 'replaceState'} caller\n */\nasync function resolve_intent(url, caller) {\n\tconst resolved = new URL(resolve_url(url));\n\n\tif (resolved.origin !== origin) {\n\t\tthrow new Error(\n\t\t\tDEV\n\t\t\t\t? `Cannot use \\`${caller}\\` with an external URL. Use \\`window.location = \"${url}\"\\` instead`\n\t\t\t\t: `${caller}: invalid URL`\n\t\t);\n\t}\n\n\tconst intent = await get_navigation_intent(resolved, false);\n\n\tif (!intent) {\n\t\tthrow new Error(\n\t\t\tDEV\n\t\t\t\t? `Cannot use \\`${caller}\\` with a URL that does not resolve to a route within the app. Use \\`window.location = \"${url}\"\\` instead`\n\t\t\t\t: `${caller}: invalid URL`\n\t\t);\n\t}\n\n\treturn intent;\n}\n\n/**\n * Allows you to navigate programmatically to a given route, with control over details such as whether scroll and focus are reset\n * (as they would be with a regular navigation) or preserved.\n *\n * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) or the state change has been applied.\n *\n * `goto` is intended for navigations to routes that belong to the app, and will reject if a route cannot be resolved.\n * For external URLs, use `window.location = url` to perform a full-page navigation instead of calling `goto(url)`.\n *","sourceCodeStart":2635,"sourceCodeEnd":2671,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/client.js#L2635-L2671","documentation":"Beyond being same-origin, navigation targets must resolve to a route defined in the app. get_navigation_intent() returns null when the resolved URL matches no route, so resolve_intent() throws to prevent the router from navigating into an undefined state. Production shows the compressed `${caller}: invalid URL` message.","triggerScenarios":"goto('/nonexistent-path') where no route matches; pushState/replaceState with a path outside the app's route table; URL misses due to trailing-slash or base-path mismatches.","commonSituations":"Typos in route paths; navigating to routes removed after refactoring; deploying under a sub-path without configuring paths.base; dynamically built URLs from user data.","solutions":["Confirm the URL matches an existing route in src/routes","Correct typos or create the missing +page.svelte route","Use window.location for URLs genuinely outside the app's routes","Check paths.base and trailing-slash configuration so the URL resolves correctly"],"exampleFix":"// before\nawait goto('/user/profile'); // no such route\n// after\nawait goto('/user/[id]'.replace('[id]', userId)); // matches src/routes/user/[id]/+page.svelte","handlingStrategy":"validation","validationCode":"// resolve against known route ids if exported, or use a simple allowlist\nconst knownRoutes = ['/', '/about', '/blog/[slug]'];\nfunction resolvesToRoute(path) {\n  return knownRoutes.some((r) => new RegExp('^' + r.replace(/\\[.+?\\]/g, '[^/]+') + '/?$').test(path));\n}","typeGuard":null,"tryCatchPattern":"try { await goto(url); } catch (e) { if (e.message.includes('invalid URL')) { window.location.assign(url); } else { throw e; } }","preventionTips":["Keep a test asserting every goto target matches a real route","Grep for goto( calls after route renames","Handle trailing-slash and base-path differences when building URLs"],"tags":["navigation","routing","sveltekit"],"backgroundTag":"unmatched-route-navigation","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}