,errorElement:,children:[{element: Solution to the problem that the Reactjs routing page is displayed as blank-PHP Chinese Network Q&A
Solution to the problem that the Reactjs routing page is displayed as blank
P粉434996845
P粉434996845 2023-09-06 16:25:53
0
1
501

I'm using Reactjs and I'm trying to use "Dynamic Routing" now, but the page appears blank. This is my routing file:

export default function Router() { return useRoutes([ { path: "/", element: , errorElement: , children: [ { element: , index: true }, { element: , index: true }, ], }, ]); } const HomePage = Loadable(lazy(() => import("../pages/HomePage"))); const User = Loadable(lazy(() => import("../pages/User"))); const Page404 = Loadable(lazy(() => import("../pages/Page404")));

I'm trying to access the "User.js" file in (src/pages), this is my User.js file:

import React, { useEffect, useState } from "react"; import { useParams, withRouter } from "react-router"; import axios from "axios"; const User = (props) => { const params = useParams(); const [users, setUsers] = useState({}); useEffect(() => { async function fetchData() { const res = await axios( `https://jsonplaceholder.typicode.com/comments/${params.id}` ); console.log("INDI", res.data); setUsers(res.data); } fetchData(); }, []); return ( <> 
Hello worldddddddd
); }; export default User;
P粉434996845
P粉434996845

reply all (1)
P粉885035114

The problem is that you addedindex=trueto both child elements. You can only have one index page

Example:

return useRoutes([ { path: "/", element: , errorElement: , children: [ { element: , index: true }, { element: }, ], }, ]); } const HomePage = Loadable(lazy(() => import("../pages/HomePage"))); const User = Loadable(lazy(() => import("../pages/User"))); const Page404 = Loadable(lazy(() => import("../pages/Page404")));

You can learn more about the purpose ofindex=truefrom theaccepted answerto this question.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!