@mandujs/core 0.9.7 → 0.9.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mandujs/core",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
4
4
  "description": "Mandu Framework Core - Spec, Generator, Guard, Runtime",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -47,9 +47,17 @@ function getGlobalRouterState(): RouterState {
47
47
  return { currentRoute: null, loaderData: undefined, navigation: { state: "idle" } };
48
48
  }
49
49
  if (!window.__MANDU_ROUTER_STATE__) {
50
+ // SSR에서 주입된 __MANDU_ROUTE__에서 초기화
51
+ const route = (window as any).__MANDU_ROUTE__;
52
+ const data = (window as any).__MANDU_DATA__;
53
+
50
54
  window.__MANDU_ROUTER_STATE__ = {
51
- currentRoute: null,
52
- loaderData: undefined,
55
+ currentRoute: route ? {
56
+ id: route.id,
57
+ pattern: route.pattern,
58
+ params: route.params || {},
59
+ } : null,
60
+ loaderData: route && data?.[route.id]?.serverData,
53
61
  navigation: { state: "idle" },
54
62
  };
55
63
  }
@@ -256,11 +264,24 @@ function handlePopState(event: PopStateEvent): void {
256
264
  const state = event.state;
257
265
 
258
266
  if (state?.routeId) {
259
- // 이미 방문한 페이지 - 데이터 다시 fetch
267
+ // Mandu로 방문한 페이지 - 데이터 다시 fetch
260
268
  navigate(window.location.pathname + window.location.search, {
261
269
  replace: true,
262
270
  scroll: false,
263
271
  });
272
+ } else {
273
+ // 직접 URL 입력 등으로 방문한 페이지 - 상태만 업데이트
274
+ const route = (window as any).__MANDU_ROUTE__;
275
+ setGlobalRouterState({
276
+ currentRoute: route ? {
277
+ id: route.id,
278
+ pattern: route.pattern,
279
+ params: route.params || {},
280
+ } : null,
281
+ loaderData: getGlobalRouterState().loaderData,
282
+ navigation: { state: "idle" },
283
+ });
284
+ notifyListeners();
264
285
  }
265
286
  }
266
287