If you already have a subscription, you can sign in.
Enjoy free content straight from your inbox 💌
00:00
Since next days uses file-based routing. A common concern people have is if a file is magically going to become a part of the public routes, this is not something you generally need to worry about. As an example, if you want a utility or a component that is only used from the demo page, it is perfectly fine to create it next to the page. Here we are creating a new component called name within the demo folder. There is actually no way that this component is magically going to become available on the public internet. There is no URLI can type over here. That will take me to that name component.
00:32
The only way that this component will become available on the internet is if we decide to explicitly use it. For example, within the demo page with this component explicitly added to our page, of course it is going to show up on that demo route. If you are concerned about utility code files conflicting with the current or future next J routing algorithms and still want to colocate them with the route set, use them. Next J provides a simple solution in the form of private folders. Any folder that starts with underscore is actually ignored by the next JS app router.
01:04
As an example, a folder named underscore UI would be ignored, and even if we create a file called Page or TSX within this folder, it is not something that the router will even look at for private folders. It doesn't matter what the names and the contents of the files under that folder are. It is not something that out is going to look at. Even with the page TSX exporting a proper next JS page demo slash UI is not going to be a valid route, and we can verify that from the browser. You can see that the next gout is returning a 4 0 4. So if you want to co-locate components next to our page
01:38
and don't want to worry about next j file naming conventions, we can simply move them into the private folder. The keen amongst you might be wondering at this point, what if you want your public route segment to start with an underscore. We know that since this folder starts with an underscore, this page is not going to become a valid route. The way around this is that instead of an explicit underscore, we can use a URL encoded version of the underscore, which is Person five F. With this change in case if you visit the slash underscore UR route, you can see that next year has successfully routed to that page.