@revojs/vue 0.1.4 → 0.1.6

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.
Files changed (2) hide show
  1. package/dist/module/app.ts +13 -7
  2. package/package.json +1 -1
@@ -1,17 +1,17 @@
1
- import { isServer, Radix, Scope, toRoutePath, useUrl, type Node } from "revojs";
1
+ import { Radix, Scope, toRoutePath, useUrl, type Node } from "revojs";
2
2
  import { type Component, createSSRApp } from "vue";
3
3
  import { createMemoryHistory, createRouter, createWebHistory, RouterView, type RouteRecordRaw } from "vue-router";
4
4
  import Main from "#alias/vue/main";
5
5
  import pages from "#virtual/pages";
6
6
 
7
- function toRoute(path: string, node: Node<Component>): RouteRecordRaw {
7
+ function toRoute(path: string, node: Node<Component>, index: number): RouteRecordRaw {
8
8
  const layout = node.children["+layout"];
9
9
 
10
10
  if (layout) {
11
11
  delete node.children["+layout"];
12
12
  }
13
13
 
14
- const children = Object.entries(node.children).map(([path, node]) => toRoute(path, node));
14
+ const children = Object.entries(node.children).map(([path, node]) => toRoute(path, node, index + 1));
15
15
 
16
16
  if (node.value && (children.length || layout)) {
17
17
  children.push({ path: "", component: node.value });
@@ -21,6 +21,10 @@ function toRoute(path: string, node: Node<Component>): RouteRecordRaw {
21
21
  path += node.parameter;
22
22
  }
23
23
 
24
+ if (index === 0) {
25
+ path = "/";
26
+ }
27
+
24
28
  const route = {
25
29
  path,
26
30
  children,
@@ -43,11 +47,13 @@ export default async (scope: Scope) => {
43
47
  }
44
48
 
45
49
  const router = createRouter({
46
- history: isServer() ? createMemoryHistory() : createWebHistory(),
47
- routes: Object.entries(radix.rootNode.children).map(([path, node]) => toRoute(path, node)),
50
+ history: import.meta.server ? createMemoryHistory() : createWebHistory(),
51
+ routes: Object.entries(radix.rootNode.children).map(([path, node]) => toRoute(path, node, 0)),
48
52
  });
49
53
 
50
- if (isServer()) {
54
+ const app = createSSRApp(Main).use(router).provide("REVOJS_SCOPE", scope);
55
+
56
+ if (import.meta.server) {
51
57
  const { pathname } = useUrl(scope);
52
58
 
53
59
  await router.push(pathname);
@@ -55,5 +61,5 @@ export default async (scope: Scope) => {
55
61
 
56
62
  await router.isReady();
57
63
 
58
- return createSSRApp(Main).use(router).provide("REVOJS_SCOPE", scope);
64
+ return app;
59
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/vue",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",