forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
124 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./modules/components/NotFoundRoute'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var merge = require('react/lib/merge'); | ||
var Route = require('./Route'); | ||
|
||
function NotFoundRoute(props) { | ||
return Route( | ||
merge(props, { | ||
path: null, | ||
catchAll: true | ||
}) | ||
); | ||
} | ||
|
||
module.exports = NotFoundRoute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require('./helper'); | ||
var RouteStore = require('../modules/stores/RouteStore'); | ||
var NotFoundRoute = require('../modules/components/NotFoundRoute'); | ||
var Route = require('../modules/components/Route'); | ||
var Routes = require('../modules/components/Routes'); | ||
|
||
var App = React.createClass({ | ||
displayName: 'App', | ||
render: function () { | ||
return React.DOM.div(); | ||
} | ||
}); | ||
|
||
describe('when registering a NotFoundRoute', function () { | ||
describe('nested inside a Route component', function () { | ||
it('becomes that Route\'s notFoundRoute', function () { | ||
var notFoundRoute; | ||
var route = Route({ handler: App }, | ||
notFoundRoute = NotFoundRoute({ handler: App }) | ||
); | ||
|
||
RouteStore.registerRoute(route); | ||
expect(route.props.notFoundRoute).toBe(notFoundRoute); | ||
RouteStore.unregisterRoute(route); | ||
}); | ||
}); | ||
|
||
describe('nested inside a Routes component', function () { | ||
it('becomes that Routes\' notFoundRoute', function () { | ||
var notFoundRoute; | ||
var routes = Routes({ handler: App }, | ||
notFoundRoute = NotFoundRoute({ handler: App }) | ||
); | ||
|
||
RouteStore.registerRoute(notFoundRoute, routes); | ||
expect(routes.props.notFoundRoute).toBe(notFoundRoute); | ||
RouteStore.unregisterRoute(notFoundRoute); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when no child routes match a URL, but the beginning of the parent\'s path matches', function () { | ||
it('matches the default route', function () { | ||
var notFoundRoute; | ||
var routes = ReactTestUtils.renderIntoDocument( | ||
Routes(null, | ||
Route({ name: 'user', path: '/users/:id', handler: App }, | ||
Route({ name: 'home', path: '/users/:id/home', handler: App }), | ||
// Make it the middle sibling to test order independence. | ||
notFoundRoute = NotFoundRoute({ handler: App }), | ||
Route({ name: 'news', path: '/users/:id/news', handler: App }) | ||
) | ||
) | ||
); | ||
|
||
var matches = routes.match('/users/5/not-found'); | ||
assert(matches); | ||
expect(matches.length).toEqual(2); | ||
|
||
expect(matches[1].route).toBe(notFoundRoute); | ||
|
||
expect(matches[0].route.props.name).toEqual('user'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters