@v-miniapp/router 1.0.5
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/README.md +63 -0
- package/dist/components/error/error-boundary.d.ts +15 -0
- package/dist/components/error/index.d.ts +1 -0
- package/dist/components/freeze/index.d.ts +11 -0
- package/dist/components/layout/index.d.ts +1 -0
- package/dist/components/layout/page-loading.d.ts +2 -0
- package/dist/components/link/index.d.ts +8 -0
- package/dist/components/router/index.d.ts +1 -0
- package/dist/components/router/pages-render.d.ts +2 -0
- package/dist/components/router/render-layout.d.ts +5 -0
- package/dist/components/router/router.d.ts +6 -0
- package/dist/components/router/style-pages-render.d.ts +2 -0
- package/dist/context/location-key.d.ts +4 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/use-app-pause.d.ts +1 -0
- package/dist/hooks/use-app-resume.d.ts +1 -0
- package/dist/hooks/use-app-state.d.ts +7 -0
- package/dist/hooks/use-did-hide.d.ts +1 -0
- package/dist/hooks/use-did-show.d.ts +1 -0
- package/dist/hooks/use-history.d.ts +2 -0
- package/dist/hooks/use-location.d.ts +1 -0
- package/dist/hooks/use-navigate.d.ts +1 -0
- package/dist/hooks/use-navigation-type.d.ts +1 -0
- package/dist/hooks/use-swipe-navigation.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2532 -0
- package/dist/stores/router.d.ts +51 -0
- package/dist/stores/router.selector.d.ts +11 -0
- package/dist/styles.css +1 -0
- package/dist/styles.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/navigation.d.ts +29 -0
- package/dist/types/router.d.ts +46 -0
- package/dist/utils/analytic.d.ts +14 -0
- package/dist/utils/animation.d.ts +4 -0
- package/dist/utils/classname.d.ts +2 -0
- package/dist/utils/deep-clone.d.ts +1 -0
- package/dist/utils/event-emitter.d.ts +11 -0
- package/dist/utils/history.d.ts +7 -0
- package/dist/utils/url.d.ts +1 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @v-miniapp/router
|
|
2
|
+
|
|
3
|
+
**@v-miniapp/router** là bộ thư viện component React mạnh mẽ được thiết kế đặc biệt cho việc phát triển Router V-MiniApp.
|
|
4
|
+
|
|
5
|
+
## Cài đặt
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @v-miniapp/router
|
|
9
|
+
# hoặc
|
|
10
|
+
pnpm add @v-miniapp/router
|
|
11
|
+
# hoặc
|
|
12
|
+
yarn add @v-miniapp/router
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Import Styles
|
|
16
|
+
|
|
17
|
+
Đảm bảo bạn import CSS từ phía component để UI hoạt động tốt nhất:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import '@v-miniapp/router/styles.css'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Ví dụ bắt đầu sử dụng
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { Router, type IRouterConfig } from '@v-miniapp/router'
|
|
27
|
+
|
|
28
|
+
// Tạo các page components
|
|
29
|
+
const HomePage = () => {
|
|
30
|
+
return <div>Trang chủ</div>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const SettingsPage = () => {
|
|
34
|
+
return <div>Cài đặt</div>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const routerConfig: IRouterConfig = {
|
|
38
|
+
// Animation giữa các pages: 'none', 'slide_up', 'slide_left', 'fade_in'
|
|
39
|
+
animation: {
|
|
40
|
+
type: 'slide_left',
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
// Keep-alive: giữ state của pages khi navigate
|
|
44
|
+
keepAlive: {
|
|
45
|
+
enable: true,
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
pages: [
|
|
49
|
+
{
|
|
50
|
+
pathname: '/home',
|
|
51
|
+
Component: HomePage,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
pathname: '/settings',
|
|
55
|
+
Component: SettingsPage,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const MiniApp = () => {
|
|
61
|
+
return <Router config={appConfig} />
|
|
62
|
+
}
|
|
63
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as React, ComponentType } from 'react';
|
|
2
|
+
type IErrorBoundaryProps = {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
Component?: ComponentType;
|
|
5
|
+
};
|
|
6
|
+
type IErrorBoundaryState = {
|
|
7
|
+
hasError: boolean;
|
|
8
|
+
error: Error | null;
|
|
9
|
+
};
|
|
10
|
+
export declare class ErrorBoundary extends React.Component<IErrorBoundaryProps, IErrorBoundaryState> {
|
|
11
|
+
constructor(props: IErrorBoundaryProps);
|
|
12
|
+
static getDerivedStateFromError(error: Error): Partial<IErrorBoundaryState>;
|
|
13
|
+
render(): string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | null | undefined;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './error-boundary';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
type ISuspenderProps = {
|
|
3
|
+
freeze: boolean;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
};
|
|
6
|
+
type IFreezeProps = ISuspenderProps & {
|
|
7
|
+
placeholder?: React.ReactNode;
|
|
8
|
+
delay?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function Freeze({ freeze, delay, children, placeholder, }: IFreezeProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './page-loading';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ComponentProps, FC } from 'react';
|
|
2
|
+
import { INavigateDeltaOptions, INavigatePathnameOptions } from '../../types';
|
|
3
|
+
export type ILinkProps = Omit<ComponentProps<'a'>, 'href' | 'onClick'> & (({
|
|
4
|
+
to: number;
|
|
5
|
+
} & INavigateDeltaOptions) | ({
|
|
6
|
+
to: string;
|
|
7
|
+
} & INavigatePathnameOptions));
|
|
8
|
+
export declare const Link: FC<ILinkProps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './router';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IRouterConfig } from '../../types/router';
|
|
2
|
+
export type IRouterConfigFunction = () => IRouterConfig;
|
|
3
|
+
export type IRouterProps = {
|
|
4
|
+
config: IRouterConfig | IRouterConfigFunction;
|
|
5
|
+
};
|
|
6
|
+
export declare const Router: ({ config }: IRouterProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './use-app-pause';
|
|
2
|
+
export * from './use-app-resume';
|
|
3
|
+
export * from './use-app-state';
|
|
4
|
+
export * from './use-did-hide';
|
|
5
|
+
export * from './use-did-show';
|
|
6
|
+
export * from './use-history';
|
|
7
|
+
export * from './use-location';
|
|
8
|
+
export * from './use-navigate';
|
|
9
|
+
export * from './use-navigation-type';
|
|
10
|
+
export * from './use-swipe-navigation';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useAppPause: (onPause: () => void) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useAppResume: (onResume: () => void) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IRouterAppState } from '../types/router';
|
|
2
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
3
|
+
export declare const useAppState: () => {
|
|
4
|
+
config: import('../types/router').IRouterConfig;
|
|
5
|
+
appState: IRouterAppState;
|
|
6
|
+
setAppState: Dispatch<SetStateAction<IRouterAppState>>;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useDidHide: (func?: () => void) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useDidShow: (func?: () => void) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useLocation: () => import('..').ILocation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useNavigate: () => import('..').INavigate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useNavigationType: () => import('..').IHistoryAction;
|