Skip to content

Commit aef0dce

Browse files
committed
[fixed] DefaultRoute/NotFoundRoute name regression
Also, added tests so we don't regress again. I believe this was introduced in c5a24a5 Fixes #870
1 parent 14fbde5 commit aef0dce

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

modules/Route.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Route {
6363
var name = options.name;
6464
var path = options.path || name;
6565

66-
if (path) {
66+
if (path && !(options.isDefault || options.isNotFound)) {
6767
if (PathUtils.isAbsolute(path)) {
6868
if (parentRoute) {
6969
invariant(

modules/components/__tests__/DefaultRoute-test.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ describe('DefaultRoute', function () {
3232

3333
Router.run(routes, '/foo', function (App) {
3434
var html = React.renderToString(<App/>);
35+
expect(html).toMatch(/Nested/);
3536
expect(html).toMatch(/Foo/);
3637
});
3738
});
3839

39-
it('renders when no siblings match', function () {
40-
var routes = (
41-
<Route path='/' handler={Nested}>
42-
<Route path='/foo' handler={Nested}>
43-
<DefaultRoute handler={Foo} />
44-
<Route path="/bar" handler={Bar} />
40+
describe('with a name', function () {
41+
it('renders when the parent route path matches', function () {
42+
var routes = (
43+
<Route path='/' handler={Nested}>
44+
<DefaultRoute name="root" handler={Foo} />
4545
</Route>
46-
</Route>
47-
);
46+
);
4847

49-
Router.run(routes, '/foo', function (App) {
50-
var html = React.renderToString(<App/>);
51-
expect(html).toMatch(/Foo/);
52-
expect(html.match(/Bar/)).toEqual(null);
48+
Router.run(routes, '/', function (App) {
49+
var html = React.renderToString(<App/>);
50+
expect(html).toMatch(/Nested/);
51+
expect(html).toMatch(/Foo/);
52+
});
5353
});
5454
});
5555

modules/components/__tests__/NotFoundRoute-test.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var { Nested, Foo, Bar } = require('../../TestUtils');
88
describe('NotFoundRoute', function () {
99

1010
describe('at the root of the config', function () {
11-
it('renders when no routes match', function () {
11+
it('renders when no other routes match', function () {
1212
var routes = <NotFoundRoute handler={Bar}/>;
1313
Router.run(routes, '/ryans-patience', function (Handler) {
1414
var html = React.renderToString(<Handler />);
@@ -18,7 +18,7 @@ describe('NotFoundRoute', function () {
1818
});
1919

2020
describe('nested in the config', function () {
21-
it('renders', function () {
21+
it('renders when none of its siblings match', function () {
2222
var routes = (
2323
<Route path='/' handler={Nested}>
2424
<Route path='/foo' handler={Foo}/>
@@ -61,4 +61,20 @@ describe('NotFoundRoute', function () {
6161
});
6262
});
6363

64+
describe('with a name', function () {
65+
it('renders when none of its siblings match', function () {
66+
var routes = (
67+
<Route path='/' handler={Nested}>
68+
<Route path='/foo' handler={Foo}/>
69+
<NotFoundRoute name="not-found" handler={Bar} />
70+
</Route>
71+
);
72+
73+
Router.run(routes, '/ryans-mind', function (Handler) {
74+
var html = React.renderToString(<Handler/>);
75+
expect(html).toMatch(/Bar/);
76+
});
77+
});
78+
});
79+
6480
});

0 commit comments

Comments
 (0)