Skip to content

How to handle errors when a basePath is specified and requests are made outside it? #112

Answered by kiliman
OllyHodgson asked this question in Q&A
Discussion options

You must be logged in to vote

The way basePath works is that it just generates routes with that prefix added, so Remix isn't doing anything special. When it sees /foo, it looks to see if there's a route and, if not, throws a not found response.

Even though you have a route/$.tsx file, remix-flat-routes is treating it like you had a bff/$.tsx route, so that's why it's not catching the invalid routes. Also, the root route is only called if Remix finds a valid route to begin with.

However, you can manually define the splat route in your config file.

const { flatRoutes } = require('remix-flat-routes')

/**
 * @type {import("@remix-run/dev").AppConfig}
 */
module.exports = {
  // ignore all files in routes folder to prevent

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@OllyHodgson
Comment options

@kiliman
Comment options

Answer selected by OllyHodgson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants