mirror of
https://github.com/rjNemo/react_template
synced 2026-06-06 07:36:42 +00:00
introduce components folder and refactor
This commit is contained in:
parent
93c909003f
commit
0aca319c24
5 changed files with 48 additions and 25 deletions
21
src/App.tsx
21
src/App.tsx
|
|
@ -1,26 +1,13 @@
|
|||
import React, { FC } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import Router from './Router';
|
||||
import logo from './assets/logo.svg';
|
||||
import { Header } from './components/Header';
|
||||
|
||||
const App: FC = () => (
|
||||
<div>
|
||||
<header>
|
||||
<nav>
|
||||
<img src={logo} alt="logo" width="50px" />
|
||||
<ul>
|
||||
<li>
|
||||
<Link to="/">Home</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="/about">About</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<>
|
||||
<Header />
|
||||
<Router />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
export default App;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,16 @@
|
|||
import React, { FC } from 'react';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
|
||||
import profileImg from './assets/about/profile.jpg';
|
||||
import { Home } from './components/Home';
|
||||
import { About } from './components/About';
|
||||
|
||||
const Router: FC = () => (
|
||||
<Switch>
|
||||
<Route exact path="/">
|
||||
<div>Hello</div>
|
||||
<Home />
|
||||
</Route>
|
||||
<Route exact path="/about">
|
||||
<div>
|
||||
<h1>About</h1>
|
||||
<div>
|
||||
<img src={profileImg} alt="profile" width="100%" />
|
||||
</div>
|
||||
</div>
|
||||
<About />
|
||||
</Route>
|
||||
</Switch>
|
||||
);
|
||||
|
|
|
|||
12
src/components/About.tsx
Normal file
12
src/components/About.tsx
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import React, { FC } from 'react';
|
||||
|
||||
import profileImg from '../assets/about/profile.jpg';
|
||||
|
||||
export const About: FC = () => (
|
||||
<div>
|
||||
<h1>About</h1>
|
||||
<div>
|
||||
<img src={profileImg} alt="profile" width="100%" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
20
src/components/Header.tsx
Normal file
20
src/components/Header.tsx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import React, { FC } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import logo from '../assets/logo.svg';
|
||||
|
||||
export const Header: FC = () => (
|
||||
<header>
|
||||
<nav>
|
||||
<img src={logo} alt="logo" width="50px" />
|
||||
<ul>
|
||||
<li>
|
||||
<Link to="/">Home</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="/about">About</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
);
|
||||
8
src/components/Home.tsx
Normal file
8
src/components/Home.tsx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import React, { FC } from 'react';
|
||||
|
||||
export const Home: FC = () => (
|
||||
<div>
|
||||
<h1>Hello</h1>
|
||||
<p>Hi there!</p>
|
||||
</div>
|
||||
);
|
||||
Loading…
Reference in a new issue