ReactJS How do you switch between pages in React?

后端 未结 3 1039
青春惊慌失措
青春惊慌失措 2021-02-12 17:45

So coming from an Angular/AngularJS background, you have states, and each state is a separate page. E.g. in a social network you can have a state with your feed, a state with a

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-12 18:40

    I'd recommend you to check react-router to solve this situation

    It easily allows you to create custom routes like this:

    import React from "react";
    import { BrowserRouter as Router, Route, Link } from "react-router-dom";
    
    const BasicExample = () => (
      
        
    • Home
    • About
    • Topics

    ); const Home = () => (

    Home

    ); const About = () => (

    About

    ); const Topics = ({ match }) => (

    Topics

    • Rendering with React
    • Components
    • Props v. State

    Please select a topic.

    } />
    ); const Topic = ({ match }) => (

    {match.params.topicId}

    ); export default BasicExample;

    For the documentation and other examples, like nested Routing, checkout this page.

提交回复
热议问题