{"record":{"id":"02f4e23d2197222f","repo":"framework7io/framework7","slug":"framework7-can-t-construct-url-for-route-with-nam","errorCode":null,"errorMessage":"Framework7: can't construct URL for route with name \"${name}\"","messagePattern":"Framework7: can't construct URL for route with name \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/modules/router/router-class.js","lineNumber":333,"sourceCode":"    }\n    const router = this;\n    const route = name ? router.findRouteByKey('name', name) : router.findRouteByKey('path', path);\n\n    if (!route) {\n      if (name) {\n        throw new Error(`Framework7: route with name \"${name}\" not found`);\n      } else {\n        throw new Error(`Framework7: route with path \"${path}\" not found`);\n      }\n    }\n    const url = router.constructRouteUrl(route, { params, query });\n\n    if (url === '') {\n      return '/';\n    }\n\n    if (!url) {\n      throw new Error(`Framework7: can't construct URL for route with name \"${name}\"`);\n    }\n    return url;\n  }\n\n  // eslint-disable-next-line\n  constructRouteUrl(route, { params, query } = {}) {\n    const { path } = route;\n    const toUrl = compile(path);\n    let url;\n    try {\n      url = toUrl(params || {});\n    } catch (error) {\n      throw new Error(\n        `Framework7: error constructing route URL from passed params:\\nRoute: ${path}\\n${error.toString()}`,\n      );\n    }\n\n    if (query) {","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/framework7io/framework7/blob/655759126686766530a027b2f8f369c991d63d1c/src/core/modules/router/router-class.js#L315-L351","documentation":"After finding a named route, `generateUrl` delegates to `constructRouteUrl`, which compiles the route path template with the given params. If `constructRouteUrl` returns an empty/falsy URL (e.g. the path template has required dynamic segments that params failed to fill), this error is thrown.","triggerScenarios":"`router.generateUrl({ name: 'item' })` for a route like `/item/:id/` without supplying `params: { id: 5 }`, so the compiled URL is empty/invalid.","commonSituations":"Routes with dynamic segments where params were forgotten or misspelled; optional param handling surprises; converting a static navigation call to a dynamic route without updating generateUrl.","solutions":["Pass the required params: `router.generateUrl({ name: 'item', params: { id: 5 } })`","Check that param keys in the call match the `:segment` names in the route path","Give the dynamic segment a default or make the route path static if params are not needed"],"exampleFix":"// before\nrouter.generateUrl({ name: 'item' }); // route: /item/:id/\n\n// after\nrouter.generateUrl({ name: 'item', params: { id: 5 } });","handlingStrategy":"validation","validationCode":"const route = router.findRouteByKey('name', name);\nif (!route) throw new Error(`Unknown route: ${name}`);\nconst required = (route.path.match(/:[^/]+/g) || []).map(s => s.slice(1));\nconst missing = required.filter(k => !(params || {})[k]);\nif (missing.length) throw new Error(`Missing params: ${missing.join(',')}`);","typeGuard":"function paramsSatisfyRoute(route, params) {\n  const required = (route.path.match(/:[^/]+/g) || []).map(s => s.slice(1));\n  return required.every(k => params && params[k] !== undefined);\n}","tryCatchPattern":"try {\n  const url = router.generateUrl({ name, params });\n} catch (e) {\n  if (/can't construct URL/.test(e.message)) {\n    console.error(`Route \"${name}\" needs params for its dynamic segments`);\n  } else throw e;\n}","preventionTips":["Always supply params for routes with :segments","Extract param names from the route path and validate before calling","Keep param keys consistent with route templates","Cover dynamic-route URL generation with unit tests"],"tags":["router","url-generation","parameters","framework7"],"backgroundTag":"missing-route-param","analyzedSha":"655759126686766530a027b2f8f369c991d63d1c","analyzedAt":"2026-09-02T19:48:40.711Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}