1

How would I set up file-based routing with tanstack router so that I could have these three different routes:

  • /{year} routes to YearViewComponent
  • /{year}/{month} routes to MonthViewComponent
  • /{year}/{month}/{day} routes to DayViewComponent

I've tried to accomplish the above by defining three file-based routes:

  • $year.$month.$day.tsx
  • $year.$month.tsx
  • $year.tsx

However, the $year.tsx component is picking up all routes, instead of allowing $year.$month to handle /2025/12 for example. How can I get $year.$month.tsx to handle /2024/12 route and $year.$month.$day to handle /2024/12/24 route?

1 Answer 1

0

The router is treating each of those as layouts rather than individual routes/files. If you don't want them to affect each other, you need to add ".index":

$year.$month.$day.index.tsx
$year.$month.index.tsx
$year.index.tsx

This will then treat each file as its own distinct route.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.