Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let devs define custom 404 page in Wasp #266

Open
Martinsos opened this issue Jun 28, 2021 · 9 comments
Open

Let devs define custom 404 page in Wasp #266

Martinsos opened this issue Jun 28, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@Martinsos
Copy link
Member

No description provided.

@Martinsos Martinsos added the enhancement New feature or request label Jun 28, 2021
@infomiho
Copy link
Contributor

infomiho commented Feb 28, 2023

We could implement it like we implemented the rootComponent #1009

app todoApp {
    client: {
        notFoundPage: import { NotFoundPage } from "@client/NotFoundPage.jsx"
    }
}

or

app todoApp {
    client: {
        notFoundPage: NotFoundPage
    }
}
page NotFoundPage {
    component: import { NotFoundPage } from "@client/NotFoundPage.jsx"
}

For React Router v5, we would need to define a new route like this:

<Route path="*">
    <NotFoundPage />
</Route>

@fecony
Copy link
Contributor

fecony commented May 13, 2023

app todoApp {
    client: {
        notFoundPage: NotFoundPage
    }
}

Maybe it would make more sense to define it for corresponding error codes? 500 / 404 / 403 / ...

app todoApp {
  client: {
    404: import { 404 } from "@client/Errors",
    500: import { 500 } from "@client/pages/errors/500"
  }
}

Also it would be cool to define single error page and get error/exception as prop to display error code/message/etc

app todoApp {
  client: {
    error: import ErrorPage from "@client/ErrorPage",
  }
}

Then in ErrorPage

export default function ErrorPage({ error }) {
  return (<h1>Oh no {error->code} occurred</h1>);
}

@Martinsos
Copy link
Member Author

Yeah I like the last idea, that is probably the best!

Aha wait, I know why we have special rule for 404 -> because that can happen by them going to wrong route and they can't handle that right now. Other errors they can't really get, those can come from server but they can handle them as they come, and as they like, in JS. Right? Or did I get something wrong here? Keep in mind this is an SPA.

@fecony
Copy link
Contributor

fecony commented May 26, 2023

Yeah I like the last idea, that is probably the best!

Aha wait, I know why we have special rule for 404 -> because that can happen by them going to wrong route and they can't handle that right now. Other errors they can't really get, those can come from server but they can handle them as they come, and as they like, in JS. Right? Or did I get something wrong here? Keep in mind this is an SPA.

Yes, makes sense. I just through about handling errors but forgot that server lives separetely
So just look at 404 error I think, However some cases like 401/403 would make sense as well, if user tries to access page but it has auth: true sooo we handle it on frontend when get user from hook

@Martinsos
Copy link
Member Author

Should we by default already have some kind of 404 handler? I think so.

@infomiho
Copy link
Contributor

infomiho commented Mar 13, 2024

The way users can implement wildcard routes in Wasp is quite simple, we might want to document this in the docs, or include it in our default template?

route WildcardRoute { path: "*", to: WildcardPage }
page WildcardPage {
  component: import { WildcardPage } from "@src/Test"
}

@Martinsos
Copy link
Member Author

The way users can implement wildcard routes in Wasp is quite simple, we might want to document this in the docs, or include it in our default template?

route WildcardRoute { path: "*", to: WildcardPage }
page WildcardPage {
  component: import { WildcardPage } from "@src/Test"
}

Just to mention that this likely then needs to be the last route in main.wasp file!

@sodic
Copy link
Contributor

sodic commented May 10, 2024

@infomiho
Copy link
Contributor

The wildcard route is a way to go, but in the current Wasp implementation, the catch-all route triggers before the OAuth route we require by Wasp to finish the OAuth flow.

We should probably move the Wasp defined routes at the first place so they don't get overridden by user-defined routes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants