Skip to Content

Routes

NextStack features a smart routing system for managing access control and to automatically generate SEO metadata.

Public Routes

Public routes are accessible by any user, regardless of whether they are logged in or not.

You can define the public routes in the src/lib/publicRoutes.ts. There, add a new object to the publicRoutes object.

This publicRoutes object is also utilized to generate the sitemap.xml, which helps search engines in indexing the website.

  • If you don’t want the client to have a public URL in the source code they can access in their browser, you can add the URL to the hiddenPublicLinks array in the src/middleware.ts file.

Private Routes

Routes not defined in publicRoutes are considered private. These routes are accessible only to logged-in users.

If an unauthenticated user attempts to access a private route, they are automatically redirected to the /auth page.

Protected Routes

Protected routes provide fine-grained control over access based on specific conditions.

A common use case involves restricting access to a route based on the user’s plan or role.

Protected routes are configured in the src/middleware.ts file. The protectedRoutes array in this file allows you to add new routes and define the condition property to specify when a user can access a route.

If a user does not meet the condition required for a route, they are redirected to the Home page (/) by default. This behavior can be easily modified in the same file.

  • Users with the admin role can access all the routes.
Last updated on