Home  >  Article  >  Web Front-end  >  How to implement jump page in react

How to implement jump page in react

藏色散人
藏色散人Original
2023-01-03 09:24:098596browse

How to implement jump page in react: 1. Introduce the button component through "import { Button } from 'antd';"; 2. Write onclick inside the button component; 3. Write the method outside render as follows "tiaozhuan(){window.location.href=""}"; 4. Use link routing; 5. Use the a tag to jump.

How to implement jump page in react

The operating environment of this tutorial: Windows 10 system, react18.0.0 version, Dell G3 computer.

How to implement jump page in react?

react project implements page jump

Update:

Use of useNavigate()

import { useNavigate } from 'react-router-dom';
  const navigate = useNavigate();
  navigate(-1)//适用于返回上级页面
  navigate('/router');//也可直接加路径

1. Use button component

First reference

import { Button } from 'antd';

Then write onclick inside the button component, and write method content outside render

class App extends Component {
tiaozhuan(){
    window.location.href="http://www.baidu.com"
   }
  render(){
  return (
    <>
    <div id="zhu" style={{ width: 400, height: 400 }}></div>
    <div id="zhe" style={{width: 600,height:400}}></div>
      <p>123 </p>
       <Button onClick={this.tiaozhuan}>跳转页面</Button>
      </>
  );  }
};
export default App;

2. Use link routing

First Quote

import { Link } from &#39;umi&#39;;

and then add the route to the page you want to jump to in this routing file

How to implement jump page in react

and then write this sentence in the return.

<Link to="/test">跳转页面</Link>

3. The simplest is a tag

<a href="#">跳转页面</a>

Recommended learning: "react video tutorial"

The above is the detailed content of How to implement jump page in react. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn