@akanjs/next 0.0.148 → 0.0.149

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bootCsr.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const bootCsr: (context: Record<string, () => Promise<unknown>>) => Promise<void>;
1
+ export declare const bootCsr: (context: Record<string, () => Promise<unknown>>, rootPath: string, entryPath?: string) => Promise<void>;
package/cjs/bootCsr.js CHANGED
@@ -38,33 +38,15 @@ var import_react = __toESM(require("react"));
38
38
  var ReactDOM = __toESM(require("react-dom/client"));
39
39
  var import_useCsrValues = require("./useCsrValues");
40
40
  const supportLanguages = ["en", "ko"];
41
- const bootCsr = async (context) => {
42
- window.document.body.style.overflow = "hidden";
43
- const pathname = window.location.pathname;
44
- if (pathname === "/404")
45
- return;
41
+ const bootCsr = async (context, rootPath, entryPath = "/route") => {
46
42
  const [, jwt] = await Promise.all([import_client.device.init({ supportLanguages }), import_client.storage.getItem("jwt")]);
47
- if (!pathname.startsWith(`/${import_client.device.lang}`))
48
- window.location.replace(`/${import_client.device.lang}${pathname}`);
49
43
  if (jwt)
50
44
  (0, import_client.initAuth)({ jwt });
51
45
  import_common.Logger.verbose(`Set default language: ${import_client.device.lang}`);
52
- const basePaths = process.env.basePaths?.split(",");
53
- const currentBasePath = basePaths ? pathname.split("/")[2] : void 0;
54
- if (currentBasePath && basePaths && !basePaths.includes(currentBasePath))
55
- throw new Error(`Invalid path: ${pathname}`);
56
- const baseLayoutPaths = ["/", "/:lang", ...currentBasePath ? [`/:lang/${currentBasePath}`] : []];
57
- const otherBasePaths = basePaths?.filter((path) => path !== currentBasePath) ?? [];
58
46
  const pages = {};
59
47
  await Promise.all(
60
48
  Object.entries(context).map(async ([key, value]) => {
61
- if (basePaths) {
62
- const pageBasePath = key.split("/")[2];
63
- if (pageBasePath && otherBasePaths.includes(pageBasePath))
64
- return;
65
- }
66
- const getPageContent = value;
67
- pages[key] = await getPageContent();
49
+ pages[key] = await value();
68
50
  })
69
51
  );
70
52
  const getPageState = (csrConfig) => {
@@ -114,10 +96,13 @@ const bootCsr = async (context) => {
114
96
  }
115
97
  });
116
98
  }
99
+ const pathname = window.location.pathname;
100
+ const initialPath = import_client.device.lang + entryPath;
101
+ window.document.body.style.overflow = "hidden";
117
102
  const getPathRoutes = (route, parentRootLayouts = [], parentLayouts = [], parentPaths = []) => {
118
103
  const parentPath = parentPaths.filter((path2) => path2 !== "/").join("");
119
104
  const currentPathSegment = /^\/\(.*\)$/.test(route.path) ? "" : route.path;
120
- const isRoot = baseLayoutPaths.includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
105
+ const isRoot = ["/", "/:lang"].includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
121
106
  const path = parentPath + currentPathSegment;
122
107
  const pathSegments = [...parentPaths, ...currentPathSegment ? [currentPathSegment] : []];
123
108
  const RootLayouts = [...parentRootLayouts, ...isRoot && route.Layout ? [route.Layout] : []];
@@ -164,9 +149,14 @@ const bootCsr = async (context) => {
164
149
  /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null)
165
150
  ));
166
151
  };
167
- const el = document.getElementById("root");
168
- if (!el)
169
- throw new Error("No root element");
170
- const root = ReactDOM.createRoot(el);
171
- root.render(/* @__PURE__ */ import_react.default.createElement(RouterProvider, null));
152
+ if (pathname !== `/${initialPath}`) {
153
+ window.location.replace(initialPath);
154
+ return;
155
+ } else {
156
+ const el = document.getElementById("root");
157
+ if (!el)
158
+ throw new Error("No root element");
159
+ const root = ReactDOM.createRoot(el);
160
+ root.render(/* @__PURE__ */ import_react.default.createElement(RouterProvider, null));
161
+ }
172
162
  };
package/esm/bootCsr.js CHANGED
@@ -11,33 +11,15 @@ import React from "react";
11
11
  import * as ReactDOM from "react-dom/client";
12
12
  import { useCsrValues } from "./useCsrValues";
13
13
  const supportLanguages = ["en", "ko"];
14
- const bootCsr = async (context) => {
15
- window.document.body.style.overflow = "hidden";
16
- const pathname = window.location.pathname;
17
- if (pathname === "/404")
18
- return;
14
+ const bootCsr = async (context, rootPath, entryPath = "/route") => {
19
15
  const [, jwt] = await Promise.all([device.init({ supportLanguages }), storage.getItem("jwt")]);
20
- if (!pathname.startsWith(`/${device.lang}`))
21
- window.location.replace(`/${device.lang}${pathname}`);
22
16
  if (jwt)
23
17
  initAuth({ jwt });
24
18
  Logger.verbose(`Set default language: ${device.lang}`);
25
- const basePaths = process.env.basePaths?.split(",");
26
- const currentBasePath = basePaths ? pathname.split("/")[2] : void 0;
27
- if (currentBasePath && basePaths && !basePaths.includes(currentBasePath))
28
- throw new Error(`Invalid path: ${pathname}`);
29
- const baseLayoutPaths = ["/", "/:lang", ...currentBasePath ? [`/:lang/${currentBasePath}`] : []];
30
- const otherBasePaths = basePaths?.filter((path) => path !== currentBasePath) ?? [];
31
19
  const pages = {};
32
20
  await Promise.all(
33
21
  Object.entries(context).map(async ([key, value]) => {
34
- if (basePaths) {
35
- const pageBasePath = key.split("/")[2];
36
- if (pageBasePath && otherBasePaths.includes(pageBasePath))
37
- return;
38
- }
39
- const getPageContent = value;
40
- pages[key] = await getPageContent();
22
+ pages[key] = await value();
41
23
  })
42
24
  );
43
25
  const getPageState = (csrConfig) => {
@@ -87,10 +69,13 @@ const bootCsr = async (context) => {
87
69
  }
88
70
  });
89
71
  }
72
+ const pathname = window.location.pathname;
73
+ const initialPath = device.lang + entryPath;
74
+ window.document.body.style.overflow = "hidden";
90
75
  const getPathRoutes = (route, parentRootLayouts = [], parentLayouts = [], parentPaths = []) => {
91
76
  const parentPath = parentPaths.filter((path2) => path2 !== "/").join("");
92
77
  const currentPathSegment = /^\/\(.*\)$/.test(route.path) ? "" : route.path;
93
- const isRoot = baseLayoutPaths.includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
78
+ const isRoot = ["/", "/:lang"].includes(parentPath + currentPathSegment) && parentRootLayouts.length < 2;
94
79
  const path = parentPath + currentPathSegment;
95
80
  const pathSegments = [...parentPaths, ...currentPathSegment ? [currentPathSegment] : []];
96
81
  const RootLayouts = [...parentRootLayouts, ...isRoot && route.Layout ? [route.Layout] : []];
@@ -137,11 +122,16 @@ const bootCsr = async (context) => {
137
122
  /* @__PURE__ */ React.createElement(React.Fragment, null)
138
123
  ));
139
124
  };
140
- const el = document.getElementById("root");
141
- if (!el)
142
- throw new Error("No root element");
143
- const root = ReactDOM.createRoot(el);
144
- root.render(/* @__PURE__ */ React.createElement(RouterProvider, null));
125
+ if (pathname !== `/${initialPath}`) {
126
+ window.location.replace(initialPath);
127
+ return;
128
+ } else {
129
+ const el = document.getElementById("root");
130
+ if (!el)
131
+ throw new Error("No root element");
132
+ const root = ReactDOM.createRoot(el);
133
+ root.render(/* @__PURE__ */ React.createElement(RouterProvider, null));
134
+ }
145
135
  };
146
136
  export {
147
137
  bootCsr
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/next",
3
- "version": "0.0.148",
3
+ "version": "0.0.149",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"