Answer the question
In order to leave comments, you need to log in
How to make SPA pages in react?
There is a Header, a side Menu, and a Content field. Made components that accept data in props, such as:
export const Header = props => (
<div className={`grid-header ${props.wide && "wide"}`}>
{props.top}
<div className="grid-header-content">{props.content}</div>
</div>
);
const Home = () => {
useEffect(() => {
document.title = "Привет";
}, []);
return (
<Page wide={true}>
<Header top={<Top />} />
<SideNav>
<LeftMenu />
</SideNav>
<Content>
<Overview />
</Content>
</Page>
);
};
Answer the question
In order to leave comments, you need to log in
Consider moving the shared elements up a level:
const App = () => {
return (
<Page wide={true}>
<Header top={<Top />} />
<SideNav>
<LeftMenu />
</SideNav>
<Content>
<Switch>
<Route path="/" component={Home} />
</Switch>
</Content>
</Page>
);
};
const PageLayout = ({ wide, top, children }) => {
return (
<Page wide={wide}>
<Header top={top ? top : <Top />} />
<SideNav>
<LeftMenu />
</SideNav>
<Content>
{children}
</Content>
</Page>
);
};
const Home = () => {
useEffect(() => {
document.title = "Привет";
}, []);
return (
<PageLayout wide>
<Overview />
</PageLayout>
);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question