kitze / mobx-router

A simple router for MobX + React apps
509 stars 66 forks source link

How to render 404 error page? #77

Closed ddinggu closed 4 years ago

ddinggu commented 5 years ago

Hi.

I want to render 404 error page when not matched routers like react-router-dom example.

I can't find any idea in this mobx-router-example or other projects.

Please help this problem. Thank you.

fastwit commented 5 years ago

Similarly to example you have provided, you can place a catch-all route at the end of your routes config,

const views = {
  home: new Route({path: '/', component: <Home />}),
  // ... all valid routes should be listed here 
  catchAll: new Route({path: '/:unknown_url', component: <ErrorPage />})
};

also, you can use onEnter to handle additional logic for exceptional cases.

ddinggu commented 5 years ago

Thanks to Reply!