Skip to content

Commit

Permalink
Move no-match handling out of resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Oct 27, 2016
1 parent e26e2eb commit 55d7213
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/createBaseRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export default function createBaseRouter({ routeConfig, matcher }) {
const routes = getRoutes(routeConfig, match);
const fullMatch = { ...match, routes, matcher, context: matchContext };

if (!routes) {
// Immediately render a "not found" error if no routes matched.
this.setState({
element: render({ ...fullMatch, error: new HttpError(404) }),
});
return;
}

try {
// ESLint doesn't handle for-await yet.
// eslint-disable-next-line semi
Expand Down
5 changes: 0 additions & 5 deletions src/resolveElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import isPromise from 'is-promise';
import React from 'react';
import warning from 'warning';

import HttpError from './HttpError';

const UNRESOLVED = {};

function checkResolved(value) {
Expand Down Expand Up @@ -73,9 +71,6 @@ function createElements(match, Components, matchData) {

export default async function* resolveElements(match) {
const { routes } = match;
if (!routes) {
throw new HttpError(404);
}

const Components = routes.map(route => (
route.getComponent ? route.getComponent(match) : route.Component
Expand Down

0 comments on commit 55d7213

Please sign in to comment.