kiliman / remix-flat-routes

Remix package to define routes using the flat-routes convention
MIT License
640 stars 22 forks source link

Different data route when using basePath #71

Closed muningis closed 10 months ago

muningis commented 10 months ago

This is config I'm using:

module.exports = {
  // ...
  ignoredRouteFiles: ["**/.*"],
  routes: (defineRoutes) => {
    return flatRoutes("routes", defineRoutes, {
      basePath: process.env.BASE_PATH,
    });
  },
};

If BASE_PATH is something like /my-path I can pass routes/_some.route.for-page/route to useRouteLoaderData() and it works If BASE_PATH is / I've to pass routes/_some.route.for-page for it to work.

And when navigating to some route, I also see that it uses either routes/_some.route.for-page/route or routes/_some.route.for-page to load the data.

node version: 18 remix-flat-routes version: 0.5.10 remix version: 1.18.1

Reproduction: https://github.com/muningis/remix-flat-routes-issue-reproduction

  1. remix.config.js has:

    // const BASE_PATH = "";
    const BASE_PATH = "/test";

    Switch between them

  2. routes/index/route.tsx has:

    {/* <div>Go to post: <Link to="/post/lorem/">Lorem</Link></div> */}
    <div>Go to post: <Link to="/test/post/lorem/">Lorem</Link></div>

Navigating to Lorem when /test is used as base path, you can see it will call http://localhost:3000/test/post/lorem/?_data=routes%2Fpost.%24slug%2Froute - and There will be data displayed

Navigating to Lorem when ` is used as base path, you can see it will callhttp://localhost:3000/post/lorem/?_data=routes%2Fpost.%24slug` - and data won't be displayed

kiliman commented 10 months ago

Hi. In your remix.config.js file, you need to ignore all files, otherwise Remix will use its convention before remix-flat-routes processes them.

Currently, you're only ignoring files that start with .. Change to ignoredRouteFiles: ["**/*"]

muningis commented 10 months ago

Yikes. I spent too much time checking docs, comparing what's in README, messing around with versions.

Yeah that's the issue.

And also, I'm pretty sure ["**/.*"] is causing initial-load (or build?) performance issues.

Thanks, and sorry for false flag.