Changeset 4a64cf0 for reactapp/src
- Timestamp:
- 07/29/22 21:31:30 (2 years ago)
- Branches:
- main
- Children:
- 3a44163
- Parents:
- 7cb8c3c
- Location:
- reactapp/src
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/Pages/Professor.js
r7cb8c3c r4a64cf0 5 5 let params = useParams(); 6 6 7 let [professor, setProfessor] = useState(); 7 let [professor, setProfessor] = useState(null); 8 let [loaded, setLoaded] = useState(null); 8 9 9 10 useEffect(() => { 10 const url = "http://192.168.0.17:8080/professor/1";11 const url = `http://192.168.0.17:8080/public/professor/${params.professorId}`; 11 12 12 13 const fetchData = async () => { … … 15 16 const json = await response.json(); 16 17 setProfessor(json); 18 setLoaded(true); 17 19 } catch (error) { 18 20 console.log("error", error); … … 23 25 }, []); 24 26 25 return (26 <div>27 if (loaded) { 28 return ( 27 29 <div> 28 30 <div>{professor.professorName}</div> 29 31 <div>{professor.faculty.facultyName}</div> 32 <Outlet /> 30 33 </div> 31 <Outlet /> 32 </div> 33 ); 34 ); 35 } else { 36 return ( 37 <div> 38 <p>loading</p> 39 <Outlet /> 40 </div> 41 ); 42 } 34 43 } 35 44 -
reactapp/src/index.js
r7cb8c3c r4a64cf0 1 1 import ReactDOM from "react-dom/client"; 2 import { 3 BrowserRouter, 4 Routes, 5 Route, 6 } from "react-router-dom"; 2 import { BrowserRouter, Routes, Route } from "react-router-dom"; 7 3 import App from "./App"; 8 import Professor from "./ Component/Professor";4 import Professor from "./Pages/Professor"; 9 5 10 const root = ReactDOM.createRoot( 11 document.getElementById("root") 12 ); 6 const root = ReactDOM.createRoot(document.getElementById("root")); 13 7 root.render( 14 8 <BrowserRouter> 15 9 <Routes> 16 10 <Route path="/" element={<App />}> 17 <Route path="professor" element={<Professor />}>11 <Route path="professor"> 18 12 <Route path=":professorId" element={<Professor />} /> 19 13 </Route>
Note:
See TracChangeset
for help on using the changeset viewer.