Fork me on GitHub

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

react 所遇到得error

<body> <div> <ul> <li> <a href="#react">React</a> </li> <li> <a href="#store">Redux</a> </li> <li> <a href="#router">React-router</a> </li> </ul> </div> <div id="react"> <h3>react错误</h3><br>

redux错误


  • store.subscribe(()=>{
        this.setState({newState})
    })
    

    redux出现的目的也是为了更方便管理 state ,实际上不需要嵌套 this.setState 。改成如下即可

    store.subscribe(()=>this.render)
    

react-router错误


路由跳转错误: 输入url但页面无法显示

error: 不能将路由配置集中配置在一个地方

由于使用react-router版本4及以上,路由配置的思想为分散配置。在选哟嵌套路由的组件中嵌套路由配置即可

<Router history={history}>
   <Route path="/page" component={ Layout } >
          <Route path="/home" component={home} />
          <Route path="content" component={content} />
   </Route>
   <Route path="/login" component={login} />
</Router>

You should not use and in the same route, will be ignored.

现象:页面无法渲染

<Router history={history}>
    <Switch>
        <Route path="/" component={layout} >
        <Route path="home" component={home} />
              <Route path="content" component={content} />
        </Route>
    </Switch>
</Router>

原因:react-router 4.0 以上报此警告

<Layout>
    <Route path="/home" component={home} />
    <Route path="/content" component={content} />
</Layout>

路由跳转错误: 使用 this.props.push('');

error: Cannot read property ‘push’ of undefined

由于使用react-router-dom5,将 history 以 props 的方式传递下去

解决:
<Layout history={history}>
      <Route exact path="/home" component={home} />
      <Route exact path="/content" component={content} />
</Layout>
</div> </body>
posted @ 2021-04-09 11:56  365/24/60  阅读(120)  评论(0编辑  收藏  举报