Gothic Framework follows a file-based routing system, similar to Next.js App Router. Folders and files in your project automatically define your routes for pages, components, and API endpoints.
When you create a file in the src/pages, src/components, or src/api folders, Gothic Framework will automatically generate the corresponding routes in src/routes/autoGenRoutes.go. This file is regenerated every time a .go or .templ file changes.
Important: The autoGenRoutes.go file is auto-generated. Do not modify it directly as your changes will be overwritten.
Here is an example of how the folder structure maps to routes:
// Folder Structure
src/
├── pages/
│ ├── index.templ → /
│ ├── about.templ → /about
│ └── docs/
│ └── guide.templ → /docs/guide
├── components/
│ └── navbar.templ → /components/navbar
└── api/
└── users.go → /api/users Each page or component that exports a RouteConfig will have its route automatically registered. The route path is derived from the file location relative to the src folder.
To customize your route behavior, you can define a RouteConfig with the route type (STATIC, DYNAMIC, or ISR), HTTP method, and middleware function:
import routes "github.com/felipegenef/gothicframework/v2/pkg/helpers/routes"
type Props = interface { }
var PageConfig = routes.RouteConfig[ Props ]{
Type: routes. STATIC ,
HttpMethod: routes. GET ,
Middleware: func (w http.ResponseWriter , r *http.Request ) Props {
return nil
},
} Want to create dynamic routes with path parameters? Click the button below to learn about path variables!