Routing System
Relevant source files
The following files were used as context for generating this wiki page:
The TAF-SAF project utilizes the file-system-based App Router provided by Next.js. This system defines the application's URL structure through the organization of files and folders within the src/app directory. The primary entry point and home page are defined by src/app/page.tsx, which corresponds to the root URL (/). The overall HTML structure and shared UI for all routes are managed by the root layout file, src/app/layout.tsx. This architecture allows for intuitive route creation and management directly within the project's file structure.
Sources: README.md:11, src/app/page.tsx, src/app/layout.tsx
Core Concepts: App Router
The project is built on Next.js version 15, as indicated by its dependencies and scripts in package.json. It specifically uses the App Router paradigm. The existence of src/app/page.tsx and src/app/layout.tsx confirms this. In this model, each folder inside the app directory can represent a route segment, and special files like page.tsx and layout.tsx define the UI for those segments.
Sources: package.json:13, src/app/page.tsx, src/app/layout.tsx
Pages
A "page" is UI that is unique to a route. A page is created by exporting a React component from a page.tsx file. In this project, the file src/app/page.tsx defines the component for the application's home page, which is accessible at the root URL (/).
Sources: src/app/page.tsx:3
Layouts
A "layout" is a UI component that is shared between multiple pages. A layout accepts a children prop that will be populated with a child layout or a child page during rendering. The file src/app/layout.tsx serves as the root layout for the entire application. It wraps every page, defining the top-level <html> and <body> tags and including global styles and fonts.
Sources: src/app/layout.tsx:22-32
The following diagram illustrates how a request for the home page is handled by composing the root layout and the home page component.
This diagram shows the rendering process where the Home page component is passed as children to the RootLayout to generate the final HTML response.
Sources: src/app/layout.tsx:29, src/app/page.tsx:3
Route Structure
The current routing structure is minimal, consisting of only the root route. New routes can be added by creating new folders within src/app and adding a page.tsx file inside them.
| File Path | URL Path | Description |
|---|---|---|
src/app/page.tsx | / | The main home page of the application. |
src/app/layout.tsx | / (and all sub-routes) | The root layout that wraps all pages. |
Sources: src/app/page.tsx, src/app/layout.tsx
The diagram below visualizes the file-system mapping to the application's routes.
This shows the basic structure where the app directory contains both the root layout and the root page.
Sources: src/app/page.tsx, src/app/layout.tsx
Configuration
Routing behavior and module resolution are influenced by configuration files at the project root.
Next.js Configuration
The next.config.ts file is used for advanced configuration of the Next.js framework. While present in the project, it is currently empty, meaning the application is running with default Next.js settings. No custom routing rules, redirects, or rewrites are configured.
// next.config.ts
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
};
export default nextConfig;
Sources: next.config.ts:1-7
TypeScript Path Aliases
The tsconfig.json file configures the TypeScript compiler. A key part of this configuration for routing and project structure is the paths alias. The alias "@/*": ["./src/*"] allows for absolute imports from the src directory, simplifying module imports within components, regardless of their depth in the file tree.
// tsconfig.json (excerpt)
"paths": {
"@/*": ["./src/*"]
}
Sources: tsconfig.json:20-22
Request and Render Flow
When a user navigates to the application's root URL, Next.js processes the request as follows:
This sequence shows the server identifying the correct layout and page files based on the URL, rendering them together, and sending the complete HTML document back to the browser.
Sources: src/app/layout.tsx, src/app/page.tsx
Conclusion
The routing system in TAF-SAF is based on the Next.js App Router, which uses a file-system convention within the src/app directory. Currently, the implementation is foundational, establishing a single root route (/) with its corresponding page (page.tsx) and a global root layout (layout.tsx). The setup is standard for a new Next.js project and provides a scalable structure for adding new routes by creating new folders and page.tsx files.
Sources: README.md, src/app/page.tsx, src/app/layout.tsx