Use resolver instead of catch-all route for errors

This commit is contained in:
Alexander Skvortsov 2021-03-25 13:40:25 -04:00
parent b5d2cbda9c
commit 058f0c50d2
3 changed files with 9 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import Page from '../../common/components/Page';
import Page from './Page';
export default class ErrorPage extends Page {
view() {

View File

@ -1,4 +1,5 @@
import Mithril from 'mithril';
import ErrorPage from '../components/ErrorPage';
/**
* Generates a route resolver for a given component.
@ -32,6 +33,13 @@ export default class DefaultResolver {
}
onmatch(args, requestedPath, route) {
const errorCode = app.data.errorCode;
const currRoute = m.route.get();
if (errorCode) {
delete app.data.errorCode;
return { view: () => ErrorPage.component({ errorCode, currRoute }) };
}
return this.component;
}

View File

@ -4,7 +4,6 @@ import PostsUserPage from './components/PostsUserPage';
import DiscussionsUserPage from './components/DiscussionsUserPage';
import SettingsPage from './components/SettingsPage';
import NotificationsPage from './components/NotificationsPage';
import ErrorPage from './components/ErrorPage';
import DiscussionPageResolver from './resolvers/DiscussionPageResolver';
/**
@ -25,8 +24,6 @@ export default function (app) {
settings: { path: '/settings', component: SettingsPage },
notifications: { path: '/notifications', component: NotificationsPage },
error: { path: '/:error', component: ErrorPage },
};
/**