kiliman / remix-flat-routes

Remix package to define routes using the flat-routes convention

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optional file extension

ivosabev opened this issue · comments

It seems impossible to create a route with optional file extension.

Eg:
/report/1
/report/1.csv

I've tried all kinds of combinations supposedly based on the docs something like report.$report([.csv]).tsx or report.$report[.]$format.tsx should work. I've also tried other combinations without success.

What am I missing?

Optional applies to the entire segment, not just a partial.

You technically need to define 2 routes. I should be able to add support for this and have it generate the 2 routes automatically.

I thought about this more and I don't believe this is possible with the current version of Remix. There are 2 main issues.

  1. Remix/RR deals with complete segments, not partial, for URL params. So you would need to parse the $report param and see if it included a file extension.

  2. Assuming that for the /report/1, you want to render the HTML report, and /reposrt/1.csv route, you want to actually just return a CSV file, that too is not possible. The reason is that a route can either be a UI route (with default export) or a Resource route (no default export). So even if your loader could determine if the route contained a file extension, Remix would still render the default component.

I think the only solution would be to create a separate route for your .csv endpoint.

Something like /report/file/1.csv