@thelacanians/vue-native-navigation 0.1.0 → 0.1.2
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 +126 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# @thelacanians/vue-native-navigation
|
|
2
|
+
|
|
3
|
+
Stack navigation for Vue Native apps. Inspired by Vue Router with a native-first API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @thelacanians/vue-native-navigation
|
|
9
|
+
# or
|
|
10
|
+
bun add @thelacanians/vue-native-navigation
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Define routes
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// app/main.ts
|
|
19
|
+
import { createApp } from 'vue'
|
|
20
|
+
import { createRouter } from '@thelacanians/vue-native-navigation'
|
|
21
|
+
import App from './App.vue'
|
|
22
|
+
import Home from './pages/Home.vue'
|
|
23
|
+
import Settings from './pages/Settings.vue'
|
|
24
|
+
|
|
25
|
+
const router = createRouter([
|
|
26
|
+
{ name: 'Home', component: Home },
|
|
27
|
+
{ name: 'Settings', component: Settings },
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
const app = createApp(App)
|
|
31
|
+
app.use(router)
|
|
32
|
+
app.start()
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Add RouterView
|
|
36
|
+
|
|
37
|
+
```vue
|
|
38
|
+
<!-- App.vue -->
|
|
39
|
+
<template>
|
|
40
|
+
<VSafeArea :style="{ flex: 1 }">
|
|
41
|
+
<RouterView />
|
|
42
|
+
</VSafeArea>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup lang="ts">
|
|
46
|
+
import { RouterView } from '@thelacanians/vue-native-navigation'
|
|
47
|
+
</script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Navigate
|
|
51
|
+
|
|
52
|
+
```vue
|
|
53
|
+
<script setup lang="ts">
|
|
54
|
+
import { useRouter } from '@thelacanians/vue-native-navigation'
|
|
55
|
+
|
|
56
|
+
const router = useRouter()
|
|
57
|
+
|
|
58
|
+
function goToSettings() {
|
|
59
|
+
router.push('Settings')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function goBack() {
|
|
63
|
+
router.back()
|
|
64
|
+
}
|
|
65
|
+
</script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Route params
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
// Pass params
|
|
72
|
+
router.push('UserProfile', { userId: '123' })
|
|
73
|
+
|
|
74
|
+
// Read params in the target screen
|
|
75
|
+
import { useRoute } from '@thelacanians/vue-native-navigation'
|
|
76
|
+
|
|
77
|
+
const route = useRoute()
|
|
78
|
+
const userId = route.value.params.userId
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## API
|
|
82
|
+
|
|
83
|
+
### `createRouter(routes)`
|
|
84
|
+
|
|
85
|
+
Creates a router instance from an array of route configs.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
interface RouteConfig {
|
|
89
|
+
name: string
|
|
90
|
+
component: Component
|
|
91
|
+
options?: {
|
|
92
|
+
title?: string
|
|
93
|
+
headerShown?: boolean
|
|
94
|
+
animation?: 'push' | 'modal' | 'fade' | 'none'
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### `useRouter()`
|
|
100
|
+
|
|
101
|
+
Returns the router instance with navigation methods:
|
|
102
|
+
|
|
103
|
+
- `push(name, params?)` - Navigate to a route
|
|
104
|
+
- `back()` - Go back one screen
|
|
105
|
+
- `replace(name, params?)` - Replace current screen
|
|
106
|
+
- `reset(name, params?)` - Reset stack to a single screen
|
|
107
|
+
|
|
108
|
+
### `useRoute()`
|
|
109
|
+
|
|
110
|
+
Returns a `ComputedRef` with the current route info:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
interface RouteLocation {
|
|
114
|
+
name: string
|
|
115
|
+
params: Record<string, any>
|
|
116
|
+
key: string
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### `<RouterView />`
|
|
121
|
+
|
|
122
|
+
Renders the current route's component with native transition animations.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thelacanians/vue-native-navigation",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Stack navigation for Vue Native apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Vue Native Contributors",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"require": "./dist/index.cjs"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
-
"files": ["dist"],
|
|
26
|
+
"files": ["dist", "README.md"],
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
29
29
|
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|