React Router 4 Match返回undefined

bp1*_*123 8 reactjs react-router-v4

我正在使用反应路由器4,我无法使用params从URL访问id.我已经按照反应路由器4文档但是当我在console.log match.params.id时返回Cannot read property 'params' of undefined.URL包含id,所以我迷路了.你可以在中找到console.logPath: Container

我究竟做错了什么?

路径: App

const App = appProps => (
  <Router>
    <div className="bgColor">
      <NavBar {...appProps} />
      <Grid className="main-page-container">
        <Switch>
          <Admin exact path="/admin/candidate_profile/:id" component={AdminCandidateProfileContainer} {...appProps} />
        </Switch>
      </Grid>
    </div>
</Router>
);

App.propTypes = {
  loggingIn: PropTypes.bool,
  authenticatedCandidate: PropTypes.bool,
  authenticatedAdmin: PropTypes.bool
};


export default createContainer(() => {
  const loggingIn = Meteor.loggingIn();
  return {
    loggingIn,
    authenticatedCandidate: !loggingIn && !!Meteor.userId() && !!Roles.userIsInRole(Meteor.userId(), 'Candidate'),
    authenticatedAdmin: !loggingIn && !!Meteor.userId() && !!Roles.userIsInRole(Meteor.userId(), 'Admin')
  };
}, App);
Run Code Online (Sandbox Code Playgroud)

路径: AdminRoute

const Admin = ({ loggingIn, authenticatedAdmin, component: Component, ...rest }) => (
  <Route
    {...rest}
    render={(props) => {
      if (loggingIn) return <div />;
      return authenticatedAdmin ?
      (<Component loggingIn={loggingIn} authenticatedAdmin={authenticatedAdmin} {...rest} />) :
      (<Redirect to="/login" />);
    }}
  />
);

Admin.propTypes = {
  loggingIn: PropTypes.bool,
  authenticatedAdmin: PropTypes.bool,
  component: PropTypes.func
};

export default Admin;
Run Code Online (Sandbox Code Playgroud)

路径: Container.js

export default CandidateProfileContainer = createContainer(({ match }) => {
  console.log('match', match.params.id);

  const profileCandidateCollectionHandle = Meteor.subscribe('admin.candidateProfile');
  const loading = !profileCandidateCollectionHandle.ready();
  const profileCandidateCollection = ProfileCandidate.findOne({ userId: Meteor.userId() });
  const profileCandidateCollectionExist = !loading && !!profileCandidateCollection;

  return {
    loading,
    profileCandidateCollection,
    profileCandidateCollectionExist,
    profileCandidate: profileCandidateCollectionExist ? profileCandidateCollection : {}
  };
}, CandidateProfilePage);
Run Code Online (Sandbox Code Playgroud)

azi*_*ium 12

你不是props来自render

const Admin = ({ loggingIn, authenticatedAdmin, component: Component, ...rest }) => (
  <Route
    {...rest}
    render={(props) => {
      if (loggingIn) return <div />;
      return authenticatedAdmin ?
      (<Component 
        loggingIn={loggingIn} 
        authenticatedAdmin={authenticatedAdmin} 
        {...rest} 
        {...props} <--- match, location are here
      />) :
      (<Redirect to="/login" />);
    }}
  />
);
Run Code Online (Sandbox Code Playgroud)