~repos /edge-city

#react#js#ssr

git clone https://pyrossh.dev/repos/edge-city.git

edge-city is a next level meta-framework for react that runs only on edge runtimes


c79eb160 Peter John

2 years ago
fix router
Files changed (3) hide show
  1. index.js +2 -1
  2. routes/index.astro +3 -2
  3. utils.js +0 -8
index.js CHANGED
@@ -48,6 +48,7 @@ const renderPage = async (filePath, url, params) => {
48
48
  "react-dom/client": "https://esm.sh/react-dom@18.2.0/client?dev",
49
49
  "react/jsx-dev-runtime": "https://esm.sh/react@18.2.0/jsx-dev-runtime?dev",
50
50
  "@/utils": "/assets/js/src/utils.js",
51
+ "@/router.js": "/assets/js/src/router.js",
51
52
  }
52
53
  }
53
54
  )
@@ -93,7 +94,7 @@ export default {
93
94
  if (localFile.includes("routes")) {
94
95
  result = await transpiler.transform(`
95
96
  import { hydrateRoot } from 'react-dom/client';
96
- import {RouterProvider} from "@/utils";
97
+ import {RouterProvider} from "@/router.js";
97
98
  import Page from "/dist/js/index.js";
98
99
 
99
100
  const initialRouteValue = JSON.parse(document.getElementById('initial_route_context').textContent);
routes/index.astro CHANGED
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  import { useState } from 'react';
3
+ import { useRouter } from '@/router.js';
3
4
 
4
5
  const head = {
5
6
  title: "pyros.sh",
@@ -9,14 +10,14 @@ const head = {
9
10
  keywords: "pyros.sh,pyrossh",
10
11
  };
11
12
 
12
- const router = {};
13
+ const router = useRouter();
13
14
  const [count, setCount] = useState(5);
14
15
  ---
15
16
 
16
17
  <div className="home-page">
17
18
  <div>
18
19
  <p>
19
- Hello from server path: {router.pathname}
20
+ Hello from server path 123: {router.pathname}
20
21
  </p>
21
22
  <div>
22
23
  <button onClick={() => setCount(count - 1)}>
utils.js CHANGED
@@ -1,11 +1,3 @@
1
- import React, { createContext, useContext } from 'react';
2
-
3
- const Context = createContext(undefined)
4
-
5
- export const RouterProvider = ({ value, children }) => {
6
- return <Context.Provider value={value}>{children}</Context.Provider>
7
- }
8
-
9
1
  export const json = async (body, status = 200, headers = {}) => {
10
2
  return new Response(body, {
11
3
  headers: {