Skip to content

Commit

Permalink
Redirect to a section in react
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosAlbaLopez committed Aug 1, 2022
1 parent d51d115 commit 518a98a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Home from "./components/Home/Home";

import PageNotFound from "./components/Pages/404Page/PageNotFound";
import ComingSoon from "./components/Pages/ComingSoon/ComingSoon";
import AboutMe from "./components/Pages/AboutMe/AboutMe.Jsx";

const App = () => {
return (
Expand All @@ -20,7 +19,7 @@ const App = () => {
<ComingSoon />
</Route>
<Route exact path="/about">
<AboutMe />
<Home section="about" />
</Route>
<Route path="/cv">
<ComingSoon />
Expand Down
15 changes: 12 additions & 3 deletions src/components/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ import GithubRepo from "../Section/GithubProjects/GithubRepo";

import PreLoader from "../../hooks/PreLoader/PreLoader";

const HomePage = () => {
const HomePage = (props) => {
const [inView, setInView] = useState("");
const [section] = useState(props.section);

useEffect(() => {
let scrollTo = document.getElementById(section);
if (scrollTo) scrollTo.scrollIntoView();
}, []);

return (
<div>
<Nav inView={inView} />
Expand All @@ -25,7 +32,7 @@ const HomePage = () => {
);
};

const Home = () => {
const Home = (props) => {
const [loading, setLoading] = useState(false);

useEffect(() => {
Expand All @@ -35,7 +42,9 @@ const Home = () => {
}, 2500);
}, []);

return <div>{loading ? <PreLoader /> : <HomePage />}</div>;
return (
<div>{loading ? <PreLoader /> : <HomePage section={props.section} />}</div>
);
};

export default Home;

0 comments on commit 518a98a

Please sign in to comment.