Skip to content

Commit

Permalink
default router
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihor-Lavrov committed Oct 5, 2024
1 parent 53f6e58 commit 4961ee4
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 44 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Pull request workflow
run-name: ${{ github.actor }} is running PR 🚀
on: pull_request
types: [opened, syncronize, reopened]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: install dependencies
run: npm install

- name: run lint
run: npm run lint-staged
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint-staged
npm run lint-staged --fix
11 changes: 8 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import pluginReact from 'eslint-plugin-react';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default [
{ files: ['**/*.{js,mjs,cjs,ts,jsx,tsx}'] },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
pluginReact.configs.flat.recommended
pluginReact.configs.flat.recommended,
{
rules: {
'react/react-in-jsx-scope': 'off'
}
}
];
56 changes: 49 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"react-router-dom": "^6.26.2"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.9.0",
Expand Down
34 changes: 6 additions & 28 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
import { RouterProvider } from 'react-router-dom';
import './App.css';
import { router } from './routes/root';

function App() {
const [count, setCount] = useState(0)

return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
<RouterProvider router={router}></RouterProvider>
</>
)
);
}

export default App
export default App;
8 changes: 8 additions & 0 deletions src/pages/error/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useRouteError } from 'react-router-dom';

export const NotFoundPage = () => {
const error = useRouteError();
console.error(error);

return <div>Error!</div>;
};
10 changes: 10 additions & 0 deletions src/pages/home/Home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Outlet } from 'react-router-dom';

export const HomePage = () => {
return (
<div>
Home Page
<Outlet />
</div>
);
};
3 changes: 3 additions & 0 deletions src/pages/home/Home1.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const Home1 = () => {
return <div>Home 1</div>;
};
1 change: 1 addition & 0 deletions src/pages/home/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Home';
1 change: 1 addition & 0 deletions src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './home';
14 changes: 14 additions & 0 deletions src/routes/root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createBrowserRouter } from 'react-router-dom';
import { HomePage } from '../pages';
import { NotFoundPage } from '../pages/error/NotFoundPage';

export const router = createBrowserRouter([
{
path: '/',
element: <HomePage />,
errorElement: <NotFoundPage />
},
{
path: '/'
}
]);

0 comments on commit 4961ee4

Please sign in to comment.