Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React路由器4匹配返回未定义_Reactjs_React Router V4 - Fatal编程技术网

Reactjs React路由器4匹配返回未定义

Reactjs React路由器4匹配返回未定义,reactjs,react-router-v4,Reactjs,React Router V4,我正在使用react router 4,使用参数从url访问id时遇到问题。但是,我遵循了react router 4文档,当I console.logmatch.params.id返回时,它无法读取未定义的属性“params”。URL包含id,所以我迷路了。您可以在Path:Container中找到console.log 我做错了什么 路径:App const App = appProps => ( <Router> <div className="bgCo

我正在使用react router 4,使用参数从url访问id时遇到问题。但是,我遵循了react router 4文档,当I console.log
match.params.id
返回
时,它无法读取未定义的属性“params”。URL包含id,所以我迷路了。您可以在
Path:Container中找到console.log

我做错了什么

路径:
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);
路径:
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);

您没有从
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" />);
    }}
  />
);
const Admin=({logging,authenticatedAdmin,component:component,…rest})=>(
{
如果(登录)返回;
返回authenticatedAdmin?
(
);
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" />);
    }}
  />
);