首页 > 解决方案 > how to go to other page when 2 selected of selecbox checked in react?

问题描述

这是我的代码:

这个app root反应

import React, { Suspense, lazy } from 'react';
import { Link, BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import './App.css';

const Home = lazy(() => import('./screen/home/Home'));
const About = lazy(() => import('./screen/about/About'));

function App() {
  return (
      <Router>
        <Suspense fallback={<div>Loading...</div>}>
          <Switch>
            <Route exact path="/" strict component={ Home }/>
            <Route path="/about" strict component={ About }/>
            <Route path="*" strict component={ () => " 404 Page Not Found " } />
          </Switch>
        </Suspense>
      </Router>
  );
}

export default App;

我的render组件像这样返回

render() {
  return(
    <input type="checkbox"
           id="a"
           name="cheker"
           value="a"
           />
           <label for="a">A</label>
    <input type="checkbox"
           id="b"
           name="cheker"
           value="b"
           />
           <label for="b">A</label>
    <input type="checkbox"
           id="c"
           name="cheker"
           value="c"
           />
           <label for="c">A</label>
   )
  }

}

componenthandlecheked喜欢这个

export default class Home extends Component{
   constructor(props){
    super(props);
    this.state = {
        postData: [], // i use this for json data
        checked: false,
        isLoading: true
    }
}

handlecheked= () => {
       // this for handle if 2 checked selecbox will go to about page
   }

标签: reactjs

解决方案


推荐阅读