Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add router #10

Merged
merged 7 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { MainPage } from './pages/MainPage';
import { Header } from './components/Header';
import { Footer } from './components/Footer';
import { Outlet } from 'react-router-dom';

export const App = () => {
return <MainPage />;
return (
<>
<Header />
<Outlet />

<Footer />
</>
);
};

export default App;
18 changes: 16 additions & 2 deletions src/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { StrictMode } from 'react';
import App from './App';
import { Provider } from 'react-redux';
import { store } from './app/store';
import { HashRouter, Routes, Route } from 'react-router-dom';
import { HashRouter, Navigate, Route, Routes } from 'react-router-dom';
import App from './App';
import { MainPage } from './pages/MainPage';
// import { PhonesPage } from './pages/PhonesPage/PhonesPage';
import { TabletsPage } from './pages/TabletspPage/TabletsPage';
import { AccessoriesPage } from './pages/AccessoriesPage/AccessoriesPage';
import { NotFoundPage } from './pages/NotFoundPage';
import { PhonesPage } from './pages/PhonesPage/PhonesPage';

export const Root = () => {
return (
Expand All @@ -12,6 +17,15 @@ export const Root = () => {
<HashRouter>
<Routes>
<Route path="/" element={<App />}>
<Route index element={<MainPage />} />
<Route path="home" element={<Navigate to="/" replace />} />
<Route path="phones">
<Route path=":phoneId?" element={<PhonesPage />} />
</Route>

<Route path="tablets" element={<TabletsPage />} />
<Route path="accessories" element={<AccessoriesPage />} />
{/* <Route path="cart" element={<CartPag />} /> */}
<Route path="*" element={<NotFoundPage />} />
</Route>
</Routes>
Expand Down
5 changes: 3 additions & 2 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { NavHeader } from './NavHeader';
import './Header.scss';
import logo from '../../img/Logo.png';
import { NavLink } from 'react-router-dom';

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
type Props = {};
Expand All @@ -10,9 +11,9 @@ export const Header: React.FC<Props> = () => {
return (
<header className="header">
<div className="header__menu">
<a href="/">
<NavLink to="/home">
<img className="header__logo" src={logo} />
</a>
</NavLink>

<NavHeader />
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/NavHeader/NavHeader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}

@include onDesktop {
bottom: -26px;
bottom: -28px;
}

background-color: #000;
Expand Down
11 changes: 7 additions & 4 deletions src/components/Header/NavHeader/NavHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import React from 'react';
import './NavHeader.scss';
import { NavLink } from 'react-router-dom';
import classNames from 'classnames';
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
type Props = {};

export const NavHeader: React.FC<Props> = () => {
const getNavLinkClass = ({ isActive }: { isActive: boolean }) =>
classNames('nav__icon', { 'nav__icon--active': isActive });
return (
<div className="nav">
<NavLink to="/" className="nav__icon nav__icon--active">
<NavLink to="/" className={getNavLinkClass}>
home
</NavLink>
<NavLink to="#" className="nav__icon">
<NavLink to="/phones" className={getNavLinkClass}>
phones
</NavLink>
<NavLink to="#" className="nav__icon">
<NavLink to="/tablets" className={getNavLinkClass}>
tablets
</NavLink>
<NavLink to="#" className="nav__icon">
<NavLink to="/accessories" className={getNavLinkClass}>
accessories
</NavLink>
</div>
Expand Down
7 changes: 7 additions & 0 deletions src/pages/AccessoriesPage/AccessoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
type Props = {};

export const AccessoriesPage: React.FC<Props> = () => {
return <>Accessories page</>;
};
7 changes: 2 additions & 5 deletions src/pages/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import React from 'react';
import './MainPage.scss';
import { Main } from '../../components/Main';
import { Header } from '../../components/Header';
import { Footer } from '../../components/Footer';
// import { Header } from '../../components/Header';
// import { Footer } from '../../components/Footer';

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
type Props = {};

export const MainPage: React.FC<Props> = () => {
return (
<>
<Header />
<div className="main-page">
<Main />
</div>

<Footer />
</>
);
};
7 changes: 7 additions & 0 deletions src/pages/PhonesPage/PhonesPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
type Props = {};

export const PhonesPage: React.FC<Props> = () => {
return <>Phones page</>;
};
7 changes: 7 additions & 0 deletions src/pages/TabletspPage/TabletsPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
type Props = {};

export const TabletsPage: React.FC<Props> = () => {
return <>Tablets page</>;
};
Loading