@vobs/router 1.2.1 → 1.3.0

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
@@ -11,7 +11,7 @@
11
11
  "type": "git",
12
12
  "url": "git+https://github.com/vobsjs/vobs.git"
13
13
  },
14
- "version": "1.2.1",
14
+ "version": "1.3.0",
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
@@ -33,8 +33,8 @@
33
33
  "./source/*": "./src/*"
34
34
  },
35
35
  "dependencies": {
36
- "@vobs/reactivity": "1.2.1",
37
- "@vobs/vobs": "1.2.1",
38
- "@vobs/runtime": "1.2.1"
36
+ "@vobs/runtime": "1.3.0",
37
+ "@vobs/reactivity": "1.3.0",
38
+ "@vobs/vobs": "1.3.0"
39
39
  }
40
40
  }
package/src/index.ts CHANGED
@@ -252,7 +252,8 @@ export interface Router {
252
252
 
253
253
  export interface RouterViewProps {
254
254
  readonly router?: Router
255
- readonly loading?: () => VobsNode | null | undefined
255
+ /** 加载占位:JSX 属性经编译器编译为惰性 getter,手写对象字面量可传节点或工厂。 */
256
+ readonly loading?: VobsNode | (() => VobsNode | null | undefined)
256
257
  readonly notFound?: (route: RouteLocation) => VobsNode | null | undefined
257
258
  readonly error?: (error: Error, retry: () => void) => VobsNode | null | undefined
258
259
  }
@@ -817,7 +818,9 @@ export function RouterView(props: RouterViewProps = {}): VobsNode {
817
818
  const route = router.currentRoute.value
818
819
  const view = router.getViewState(route)
819
820
  routeRetry = view.retry
820
- if (view.status === 'loading') return props.loading?.() ?? null
821
+ if (view.status === 'loading') {
822
+ return (typeof props.loading === 'function' ? props.loading() : props.loading) ?? null
823
+ }
821
824
  if (view.status === 'not-found') return props.notFound?.(route) ?? null
822
825
  if (view.status === 'error') {
823
826
  throw view.error ?? new Error('路由组件加载失败')