{"record":{"id":"e1c863bc09ecedd9","repo":"framework7io/framework7","slug":"framework7-it-is-not-allowed-to-use-router-method","errorCode":null,"errorMessage":"Framework7: it is not allowed to use router methods on global app router. Use router methods only on related View, e.g. app.views.main.router.${method}(...)","messagePattern":"Framework7: it is not allowed to use router methods on global app router\\. Use router methods only on related View, e\\.g\\. app\\.views\\.main\\.router\\.(.+?)\\(\\.\\.\\.\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/modules/router/app-router-check.js","lineNumber":3,"sourceCode":"export default function appRouterCheck(router, method) {\n  if (!router.view) {\n    throw new Error(\n      `Framework7: it is not allowed to use router methods on global app router. Use router methods only on related View, e.g. app.views.main.router.${method}(...)`,\n    );\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":8,"githubUrl":"https://github.com/framework7io/framework7/blob/655759126686766530a027b2f8f369c991d63d1c/src/core/modules/router/app-router-check.js#L1-L8","documentation":"The app-level router exists but is not attached to any View, so navigation methods have no target container. Framework7 throws when a router method (navigate, back, etc.) is invoked on it, and the thrown message tells you to use a View's router instead.","triggerScenarios":"Calling `app.router.navigate('/page/')`, `app.router.back()`, `app.router.refreshPage()` etc. directly on the global app router instead of `app.views.main.router`.","commonSituations":"Copy-pasted code using `app.router` from tutorials; helper functions receiving the app instead of the view router; refactors that dropped the `.views.main` segment.","solutions":["Call the method on a View's router, e.g. `app.views.main.router.navigate('/page/')`","Pass the view router into helpers instead of the app instance","If you have multiple views, pick the correct one: app.views[name].router"],"exampleFix":"// before\napp.router.navigate('/about/');\n\n// after\napp.views.main.router.navigate('/about/');","handlingStrategy":"type-guard","validationCode":"function assertViewRouter(router, method) {\n  if (!router || !router.view) {\n    throw new Error(`Use a View router (e.g. app.views.main.router.${method}()), not app.router`);\n  }\n}","typeGuard":"function isViewRouter(router) {\n  return !!router && 'view' in router && !!router.view;\n}","tryCatchPattern":"try {\n  app.views.main.router.navigate('/about/');\n} catch (e) {\n  if (/global app router/.test(e.message)) {\n    console.error('Call router methods on a View router, e.g. app.views.main.router');\n  } else throw e;\n}","preventionTips":["Never call app.router.* directly; always go through a View's router","Wrap navigation helpers to accept a router and assert isViewRouter first","Search codebase for `app.router.` during review","Use app.views.main (or the appropriate view) consistently"],"tags":["router","navigation","api-misuse","framework7"],"backgroundTag":"router-method-on-wrong-target","analyzedSha":"655759126686766530a027b2f8f369c991d63d1c","analyzedAt":"2026-09-02T19:48:40.711Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}