framework7io/framework7 · error · Error
Framework7: it is not allowed to use router methods on globa
Error message
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}(...) What it means
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.
Source
Thrown at src/core/modules/router/app-router-check.js:3
export default function appRouterCheck(router, method) {
if (!router.view) {
throw new Error(
`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}(...)`,
);
}
}
View on GitHub (pinned to 6557591266)
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
Example fix
// before
app.router.navigate('/about/');
// after
app.views.main.router.navigate('/about/'); Defensive patterns
Strategy: type-guard
Validate before calling
function assertViewRouter(router, method) {
if (!router || !router.view) {
throw new Error(`Use a View router (e.g. app.views.main.router.${method}()), not app.router`);
}
} Type guard
function isViewRouter(router) {
return !!router && 'view' in router && !!router.view;
} Try / catch
try {
app.views.main.router.navigate('/about/');
} catch (e) {
if (/global app router/.test(e.message)) {
console.error('Call router methods on a View router, e.g. app.views.main.router');
} else throw e;
} Prevention
- 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
When it happens
Trigger: Calling `app.router.navigate('/page/')`, `app.router.back()`, `app.router.refreshPage()` etc. directly on the global app router instead of `app.views.main.router`.
Common situations: 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.
Related errors
- Framework7: There is no View with "${anotherViewName}" name
- Framework7: "name" or "path" parameter is required
- Framework7: route with name "${name}" not found
- Framework7: route with path "${path}" not found
- Framework7: can't construct URL for route with name "${name}
AI-assisted analysis of framework7io/framework7@6557591266 (2026-09-02).
Data as JSON: /api/errors/e1c863bc09ecedd9.
Report an issue: GitHub.