How to implement jump page in react

藏色散人
Release: 2023-01-04 16:41:14
Original
8597 people have browsed it

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');//也可直接加路径
Copy after login

1. Use button component

First reference

import { Button } from 'antd';
Copy after login

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;
Copy after login

2. Use link routing

First Quote

import { Link } from &#39;umi&#39;;
Copy after login

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>
Copy after login

3. The simplest is a tag

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template