Menu

#148 [question] [feature] File-based routing

open
nobody
question (13)
2025-10-04
2025-10-03
Anonymous
No

Originally created by: endernoke

Is your feature request related to a problem? Please describe.
In the TypeScript client, we use pastel to organize subcommands and arguments in a file-based manner.
But inside TUI subcommands like chat, we have to use a lot of state variables to conditionally render different pages/views based on the user's state, e.g. chat menu vs messaging interface, normal login vs challenge required, etc. This makes UI rendering logic more complex as the project grows.

Describe the solution you'd like
Implement a navigation router (like react-router) and a next.js like file-based routing mechanism for TUI views.
It should:

  • Allow Ink components to navigate to a different view with an API, e.g. router.replace("/chat/menu")
  • Have a history API, e.g. router.replace(), router.push(), router.back(), etc.
  • Render a view in the corresponding file for different paths
    e.g. For a directory structure like this:
    routes/ |-- login/ | |-- index.tsx | |-- challenge/ | |-- index.tsx |-- index.tsx
    router.push("/") would render routes/index.tsx; router.push("/login/challenge") would render routes/login/challenge/index.tsx
  • Allow wild card matching like [id] in next.js (optional but preferred)

Describe alternatives you've considered
Keep logic for view rendering with custom logic in components, but this introduces two issues:

  • Complex UI logic that's harder to follow and understand
  • Difficult to test
  • Implementing sophisticated view management is challenging, e.g. opening a shared post in chat, do something that goes to another view, then returning to the chat after viewing the post.

Additional context
Pastel uses commands as a special directory which contains subcommands so we can adopt a similar approach and dedicate a directory like routes or pages to be handled by the router.

Fellow instagramers please let me know if this proposal would make the development experience better. Feel free to roast its architecture/design/usefulness.

Discussion

  • Anonymous

    Anonymous - 2025-10-03

    Originally posted by: supreme-gg-gg

    +1, this would be super useful for the Ink OSS community when building terminal apps (not just CLI tools), doesn't seem like a good alternative exists really

     
  • Anonymous

    Anonymous - 2025-10-04

    Originally posted by: endernoke

    This seems promising
    https://github.com/vadimdemedes/ink/issues/396

     

Log in to post a comment.

Monday.com Logo