ReactJS How do you switch between pages in React?

后端 未结 3 1040
青春惊慌失措
青春惊慌失措 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:26

    Another solution. Files index.js and product.js are in the directory src\pages. For more information watch video https://www.youtube.com/watch?v=hjR-ZveXBpQ.

    file App.js

    import React from "react";
    import {
      BrowserRouter as Router,
      Route,
      Switch
    } from "react-router-dom";
    import Products from "./pages"
    import Product from "./pages/product"
    
    const App = () => {
      return (
        
          
            
            
          
        
      );
    }
    
    export default App;
    

    file index.js

    import React from "react";
    import {Link} from "react-router-dom";
    const Products = () => {
      return (
        

    Products

    Go to product
    ); }; export default Products;

    file product.js

    import React from "react";
    const Product = () => {
      return (
        

    Product !!!!!!

    ); } export default Product;

提交回复
热议问题