my localhost window is loading indefinitely, if i dont put the return right next to the
function App() {
but since i want to put stuff inbetween, it completly shuts down. Why is this the case? Please help
`
/* eslint-disable default-case */
import './App.css';
import Navbar from './Navbar';
import About from './pages/About';
import Pricing from './pages/Pricing';
function App() {
let Component
switch (window.location.pathname) {
case "/":
Component = <App />
break
case "/pricing":
Component = <Pricing />
break
case "/about":
Component = <About />
break
}
return (<><Navbar />{Component}</>)
}
export default App;
`
if i put only
`
/* eslint-disable default-case */
import './App.css';
import Navbar from './Navbar';
import About from './pages/About';
import Pricing from './pages/Pricing';
function App() {return (<><Navbar /></>)
}
export default App;
`
then it works. It works fine if i remove the {Component} at the end.
EDIT: FOUND THE PROBLEM. I called the wrong component. Dumb mistake of mine. Ty for your time
2
Answers
Try like this:
Not an expert in React but I think you cannot use
<Pricing />
, for example, outside of the scope of the return.So just do it like so
Component = Pricing
and call the the component as<Component/>
inside the scope of the return.I have a similar code that works and goes like this:
Hope this helps!
In you code, you are calling App component recursively try below solution
replace below code
with