From e26e1f10c076579c280935dbcc29e49737c0b628 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 26 Apr 2017 18:34:28 +0200 Subject: [PATCH] docs: URL Param + Variadic route doc (#1813) --- docs/route.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/route.md b/docs/route.md index d5a9c83a..518f248d 100644 --- a/docs/route.md +++ b/docs/route.md @@ -319,6 +319,20 @@ m.route(document.body, "/edit/pictures/image.jpg", { }) ``` +#### Handling 404s + +For isomorphic / universal javascript app, an url param and a variadic route combined is very usefull to display custom 404 error page. + +In a case of 404 Not Found error, the server send back the custom page to client. When Mithril is loaded, it will redirect client to the default route because it can't know that route. + +```javascript +m.route(document.body, "/", { + "/": homeComponent, + // [...] + "/:404...": errorPageComponent +}); + ``` + #### History state It's possible to take full advantage of the underlying `history.pushState` API to improve user's navigation experience. For example, an application could "remember" the state of a large form when the user leaves a page by navigating away, such that if the user pressed the back button in the browser, they'd have the form filled rather than a blank form.