Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Documentation on pathless layout routes VS. pathless route group directories#5530

nednella started this conversation inGeneral
Discussion options

Hello

I'd like to know if I'm reading the docs correctly regardingpathless layout routes andpathless route group directories.

This is something that has been asked about multiple times with zero clarification. See similar discussions:#4975,#4319,#3837.

Example

Below is a screenshot of a mock routing structure.

The application is grouped as:

  • (app) - the application itself.
  • (auth) - the public pages, including the landing page and auth pages, that can only be accessed prior to authenticating. Else, the user is redirected to/home.
  • (onboarding) - some mock onboarding process that a newly registered user must complete before accessing the application.
imageimage

Note that in this example, therouteToken has been updated as follows:routeToken: "_layout",.

Required behaviour

Each group will have it's own layout file which provides1) abeforeLoad function to check authentication and/or onboarding state, and2) a layout for said group.

Obtaining the required behaviour

According to the docs regardling pathless layouts and pathless route groups, to get this expected behaviour, I would need to use a pathless layout structure, e.g.,

_app/    posts/    profile/    home.tsx    _auth/    index.tsx    login.tsx    register.tsx    sso-callback.tsx    _onboarding/    onboarding.tsx    ..._app.tsx_auth.tsx_onboarding.tsx__root.tsx

Where each set of pages has it's own pathless layout file at theroutes/ root, which provides both thebeforeLoad check and the layout structure.

My confusion

However, the example above using pathless route groups with a nested_layout.tsx file withindoes also provide the expected behaviour.

The docs clearly state the following regarding pathless route group directories:They are purely organizational and do not affect the route tree or component tree in any way..

If they (to my knowledge) both work the same,1) why do the docs not reflect this?2) what's the point in supporting both methods?

Any light shed on this would be great. I'm pleased that I can get the expected behaviour using route groups as I do quite like the NextJS file routing, but I'm very confused as to why the docs urge you towards using pathless layout routes.

Edit: there's prior discussion where@schiller-manuel also indicates that route groups are again,purely organisational, and do not influence anything.

Edit: included a devtools screenshot for additional context.

TIA

You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
1 participant
@nednella

[8]ページ先頭

©2009-2025 Movatter.jp