Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix <Route component /> type #6327

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/react-router/modules/Route.js
@@ -1,5 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import PropTypesElementType from "prop-types-elementtype";
import invariant from "invariant";
import warning from "warning";

Expand Down Expand Up @@ -127,7 +128,7 @@ class Route extends React.Component {
if (__DEV__) {
Route.propTypes = {
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
component: PropTypes.func,
component: PropTypesElementType,
exact: PropTypes.bool,
location: PropTypes.object,
path: PropTypes.string,
Expand Down
35 changes: 35 additions & 0 deletions packages/react-router/modules/__tests__/Route-test.js
Expand Up @@ -127,6 +127,41 @@ describe("A <Route>", () => {
});
});

it("receives { match, location, history } props", () => {
let actual = null;
const Component = props => (actual = props) && null;

ReactDOM.render(
<Router history={history}>
<Route path="/" component={Component} />
</Router>,
node
);

expect(actual.history).toBe(history);
expect(typeof actual.match).toBe("object");
expect(typeof actual.location).toBe("object");
});

it("support forwardRef component", () => {
// Make sure the component PropTypes is not throwing a warning
// forwardRef are generated by React and not a function
const TEXT = "Mrs. Kato";
const node = document.createElement("div");
const Component = React.forwardRef((props, ref) => (
<div ref={ref}>{TEXT}</div>
));

ReactDOM.render(
<Router history={history}>
<Route path="/" component={Component} />
</Router>,
node
);

expect(node.innerHTML).toContain(TEXT);
});

describe("with `exact=true`", () => {
it("renders when the URL does not have a trailing slash", () => {
const text = "bubblegum";
Expand Down
1 change: 1 addition & 0 deletions packages/react-router/package.json
Expand Up @@ -47,6 +47,7 @@
"loose-envify": "^1.3.1",
"path-to-regexp": "^1.7.0",
"prop-types": "^15.6.1",
"prop-types-elementtype": "^1.0.0",
"warning": "^4.0.1"
},
"devDependencies": {
Expand Down