Introduction
Godot Router is a file-based routing system for Godot 4, inspired by the file-based routing conventions of SvelteKit. It lets you organize your Godot scenes in a routes directory, using special filenames like +page.tscn and +layout.tscn for automatic URL mapping and navigation.
Motivation
Godot's scene system is powerful, but managing navigation and nested layouts in large projects can become complex. Godot Router brings a familiar, web-inspired routing approach to Godot, making it easier to build modular, scalable projects with clean navigation patterns.
Details
The plugin offers an autoloaded Router node. This allows any script to call Router.goto(url: String) to change the navigation. Instead of directly changing scenes, nodes are swapped out to account for layouts. layouts are scenes that wrap multiple pages, such as a navigation bar to swap between all the settings scenes.
Below is an example of the file structure.
routes
├── +layout.tscn
├── (menu)
│ ├── +layout.tscn
│ ├── +page.tscn (main route)
│ └── (settings)
│ ├── +layout.tscn
│ ├── audio
│ │ └── +page.tscn
│ ├── gameplay
│ │ └── +page.tscn
│ └── controls
│ └── +page.tscn
└── (levels)
├── +layout.tscn
├── level-1
│ └── +page.tscn
├── level-2
│ └── +page.tscn
└── level-3
└── +page.tscn Conclusion
This project was surprisingly simple to create and the layouts are a powerful addition that simplify scene architecture.