Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
React-router route.lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
pudek357 committed Aug 15, 2024
1 parent 21afeab commit 6cd026e
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 253 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload dist folder
path: "./dist"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
.DS_Store
# dist
dist
dist-ssr
*.local
1 change: 0 additions & 1 deletion docs/assets/Bar-a2943911.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/assets/Foo-f4586d09.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/assets/Root-4b3afa67.js

This file was deleted.

226 changes: 0 additions & 226 deletions docs/assets/index-7e6ee8dc.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/assets/index-b5fedda1.css

This file was deleted.

14 changes: 0 additions & 14 deletions docs/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"dev": "vite",
"build": "tsc && vite build && mv dist docs",
"build": "tsc && vite build",
"serve": "vite preview"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/RootLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export const RootLayout = () => {
<div className="main-content">
<div className="sidebar">
<div>
<Link to="/">root</Link>
<Link to="/react-router-route-lazy/">root</Link>
</div>
<div>
<Link to="/foo">foo</Link>
<Link to="/react-router-route-lazy/foo">foo</Link>
</div>
<div>
<Link to="/bar">bar</Link>
<Link to="/react-router-route-lazy/bar">bar</Link>
</div>
</div>

Expand Down
16 changes: 12 additions & 4 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import {
createBrowserRouter,
redirect,
RouterProvider,
} from "react-router-dom";
import { RootLayout } from "./RootLayout";
import "./index.css";

Expand All @@ -7,17 +11,21 @@ let router = createBrowserRouter([
element: <RootLayout />,
children: [
{
path: "/",
path: "/react-router-route-lazy/",
lazy: () => import("./Root"),
},
{
path: "/foo",
path: "/react-router-route-lazy/foo",
lazy: () => import("./Foo"),
},
{
path: "/bar",
path: "/react-router-route-lazy/bar",
lazy: () => import("./Bar"),
},
{
path: "*",
loader: () => redirect("/react-router-route-lazy/"),
},
],
},
]);
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import rollupReplace from "@rollup/plugin-replace";

// https://vitejs.dev/config/
export default defineConfig({
base: "/react-router-route-lazy/",
server: {
port: 3000,
},
Expand Down

0 comments on commit 6cd026e

Please sign in to comment.