Skip to content

Commit

Permalink
[fixed] DefaultRoute/NotFoundRoute name regression
Browse files Browse the repository at this point in the history
Also, added tests so we don't regress again.

I believe this was introduced in c5a24a5

Fixes remix-run#870
  • Loading branch information
mjackson committed Feb 24, 2015
1 parent 14fbde5 commit aef0dce
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion modules/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Route {
var name = options.name;
var path = options.path || name;

if (path) {
if (path && !(options.isDefault || options.isNotFound)) {
if (PathUtils.isAbsolute(path)) {
if (parentRoute) {
invariant(
Expand Down
24 changes: 12 additions & 12 deletions modules/components/__tests__/DefaultRoute-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ describe('DefaultRoute', function () {

Router.run(routes, '/foo', function (App) {
var html = React.renderToString(<App/>);
expect(html).toMatch(/Nested/);
expect(html).toMatch(/Foo/);
});
});

it('renders when no siblings match', function () {
var routes = (
<Route path='/' handler={Nested}>
<Route path='/foo' handler={Nested}>
<DefaultRoute handler={Foo} />
<Route path="/bar" handler={Bar} />
describe('with a name', function () {
it('renders when the parent route path matches', function () {
var routes = (
<Route path='/' handler={Nested}>
<DefaultRoute name="root" handler={Foo} />
</Route>
</Route>
);
);

Router.run(routes, '/foo', function (App) {
var html = React.renderToString(<App/>);
expect(html).toMatch(/Foo/);
expect(html.match(/Bar/)).toEqual(null);
Router.run(routes, '/', function (App) {
var html = React.renderToString(<App/>);
expect(html).toMatch(/Nested/);
expect(html).toMatch(/Foo/);
});
});
});

Expand Down
20 changes: 18 additions & 2 deletions modules/components/__tests__/NotFoundRoute-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var { Nested, Foo, Bar } = require('../../TestUtils');
describe('NotFoundRoute', function () {

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

describe('nested in the config', function () {
it('renders', function () {
it('renders when none of its siblings match', function () {
var routes = (
<Route path='/' handler={Nested}>
<Route path='/foo' handler={Foo}/>
Expand Down Expand Up @@ -61,4 +61,20 @@ describe('NotFoundRoute', function () {
});
});

describe('with a name', function () {
it('renders when none of its siblings match', function () {
var routes = (
<Route path='/' handler={Nested}>
<Route path='/foo' handler={Foo}/>
<NotFoundRoute name="not-found" handler={Bar} />
</Route>
);

Router.run(routes, '/ryans-mind', function (Handler) {
var html = React.renderToString(<Handler/>);
expect(html).toMatch(/Bar/);
});
});
});

});

0 comments on commit aef0dce

Please sign in to comment.