Skip to content

Commit 8669c49

Browse files
committed
docs(api): add history functions
1 parent 9373e29 commit 8669c49

File tree

5 files changed

+121
-88
lines changed

5 files changed

+121
-88
lines changed

docs/api/index.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,94 @@ When a `<router-view>` has a `name`, it will render the component with the corre
142142
### route
143143

144144
- type: `RouteLocationNormalizedLoaded`. A route ___location that has all of its component resolved (if any was lazy loaded) so it can be displayed.
145+
146+
## createRouter
147+
148+
Creates a Router instance that can be used by a Vue app.
149+
150+
**Signature:**
151+
152+
```typescript
153+
export declare function createRouter(options: RouterOptions): Router
154+
```
155+
156+
### Parameters
157+
158+
| Parameter | Type | Description |
159+
| --------- | ------------------------------------------------------- | -------------------------------- |
160+
| options | [`RouterOptions`](./vue-router-interface#routeroptions) | Options to initialize the router |
161+
162+
## createWebHistory
163+
164+
Creates an HTML5 history. Most common history for single page applications. The application must be served through the http protocol.
165+
166+
**Signature:**
167+
168+
```typescript
169+
export declare function createWebHistory(base?: string): RouterHistory
170+
```
171+
172+
### Parameters
173+
174+
| Parameter | Type | Description |
175+
| --------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
176+
| base | `string` | optional base to provide. Useful when the application is hosted inside of a folder like `https://example.com/folder/` |
177+
178+
### Examples
179+
180+
```js
181+
createWebHistory() // No base, the app is hosted at the root of the ___domain
182+
createWebHistory('/folder/') // gives a url of `https://example.com/folder/`
183+
```
184+
185+
## createWebHashHistory
186+
187+
Creates a hash history. Useful for web applications with no host (e.g. `file://`) or when configuring a server to handle any URL.
188+
189+
**Signature:**
190+
191+
```typescript
192+
export declare function createWebHashHistory(base?: string): RouterHistory
193+
```
194+
195+
### Parameters
196+
197+
| Parameter | Type | Description |
198+
| --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
199+
| base | `string` | optional base to provide. Defaults to `___location.pathname` or `/` if at root. If there is a `base` tag in the `head`, its value will be **ignored**. |
200+
201+
### Examples
202+
203+
```js
204+
// at https://example.com/folder
205+
createWebHashHistory() // gives a url of `https://example.com/folder#`
206+
createWebHashHistory('/folder/') // gives a url of `https://example.com/folder/#`
207+
// if the `#` is provided in the base, it won't be added by `createWebHashHistory`
208+
createWebHashHistory('/folder/#/app/') // gives a url of `https://example.com/folder/#/app/`
209+
// you should avoid doing this because it changes the original url and breaks copying urls
210+
createWebHashHistory('/other-folder/') // gives a url of `https://example.com/other-folder/#`
211+
212+
// at file:///usr/etc/folder/index.html
213+
// for locations with no `host`, the base is ignored
214+
createWebHashHistory('/iAmIgnored') // gives a url of `file:///usr/etc/folder/index.html#`
215+
```
216+
217+
## createMemoryHistory
218+
219+
Creates a in-memory based history. The main purpose of this history is to handle SSR. It starts in a special ___location that is nowhere. It's up to the user to replace that ___location with the starter ___location.
220+
221+
**Signature:**
222+
223+
```typescript
224+
export declare function createMemoryHistory(base?: string): RouterHistory
225+
```
226+
227+
### Parameters
228+
229+
| Parameter | Type | Description |
230+
| --------- | ------ | ----------------------------------------- |
231+
| base | string | Base applied to all urls, defaults to '/' |
232+
233+
### Returns
234+
235+
a history object that can be passed to the router constructor

docs/api/vue-router-function.md

Lines changed: 22 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,5 @@
11
# Function
22

3-
## createMemoryHistory
4-
5-
Creates a in-memory based history. The main purpose of this history is to handle SSR. It starts in a special ___location that is nowhere. It's up to the user to replace that ___location with the starter ___location.
6-
7-
**Signature:**
8-
```typescript
9-
export declare function createMemoryHistory(base?: string): RouterHistory;
10-
```
11-
12-
### Parameters
13-
14-
| Parameter | Type | Description |
15-
| --- | --- | --- |
16-
| base | string | Base applied to all urls, defaults to '/' |
17-
18-
### Returns
19-
20-
a history object that can be passed to the router constructor
21-
22-
## createRouter
23-
24-
Create a Router instance that can be used on a Vue app.
25-
26-
**Signature:**
27-
```typescript
28-
export declare function createRouter(options: RouterOptions): Router;
29-
```
30-
31-
### Parameters
32-
33-
| Parameter | Type | Description |
34-
| --- | --- | --- |
35-
| options | RouterOptions | [RouterOptions](./vue-router-interface#routeroptions) |
36-
37-
## createWebHashHistory
38-
39-
Creates a hash history.
40-
41-
**Signature:**
42-
```typescript
43-
export declare function createWebHashHistory(base?: string): RouterHistory;
44-
```
45-
46-
### Parameters
47-
48-
| Parameter | Type | Description |
49-
| --- | --- | --- |
50-
| base | string | optional base to provide. Defaults to `___location.pathname` or `/` if at root. If there is a `base` tag in the `head`, its value will be **ignored**. |
51-
52-
### Examples
53-
54-
55-
```js
56-
// at https://example.com/folder
57-
createWebHashHistory() // gives a url of `https://example.com/folder#`
58-
createWebHashHistory('/folder/') // gives a url of `https://example.com/folder/#`
59-
// if the `#` is provided in the base, it won't be added by `createWebHashHistory`
60-
createWebHashHistory('/folder/#/app/') // gives a url of `https://example.com/folder/#/app/`
61-
// you should avoid doing this because it changes the original url and breaks copying urls
62-
createWebHashHistory('/other-folder/') // gives a url of `https://example.com/other-folder/#`
63-
64-
// at file:///usr/etc/folder/index.html
65-
// for locations with no `host`, the base is ignored
66-
createWebHashHistory('/iAmIgnored') // gives a url of `file:///usr/etc/folder/index.html#`
67-
```
68-
69-
703
## createWebHistory
714

725
## isNavigationFailure
@@ -75,75 +8,78 @@ createWebHashHistory('/iAmIgnored') // gives a url of `file:///usr/etc/folder/in
758

769
## onBeforeRouteLeave
7710

78-
Add a navigation guard that triggers whenever the component for the current ___location is about to be left. Similar to but can be used in any component. The guard is removed when the component is unmounted.
11+
Add a navigation guard that triggers whenever the component for the current ___location is about to be left. Similar to but can be used in any component. The guard is removed when the component is unmounted.
7912

8013
**Signature:**
14+
8115
```typescript
82-
export declare function onBeforeRouteLeave(leaveGuard: NavigationGuard): void;
16+
export declare function onBeforeRouteLeave(leaveGuard: NavigationGuard): void
8317
```
8418

8519
### Parameters
8620

87-
| Parameter | Type | Description |
88-
| --- | --- | --- |
21+
| Parameter | Type | Description |
22+
| ---------- | --------------- | --------------------------------------------------------- |
8923
| leaveGuard | NavigationGuard | [NavigationGuard](./vue-router-interface#navigationguard) |
9024

9125
## onBeforeRouteUpdate
9226

93-
Add a navigation guard that triggers whenever the current ___location is about to be updated. Similar to but can be used in any component. The guard is removed when the component is unmounted.
27+
Add a navigation guard that triggers whenever the current ___location is about to be updated. Similar to but can be used in any component. The guard is removed when the component is unmounted.
9428

9529
**Signature:**
30+
9631
```typescript
97-
export declare function onBeforeRouteUpdate(updateGuard: NavigationGuard): void;
32+
export declare function onBeforeRouteUpdate(updateGuard: NavigationGuard): void
9833
```
9934

10035
### Parameters
10136

102-
| Parameter | Type | Description |
103-
| --- | --- | --- |
37+
| Parameter | Type | Description |
38+
| ----------- | --------------- | --------------------------------------------------------- |
10439
| updateGuard | NavigationGuard | [NavigationGuard](./vue-router-interface#navigationguard) |
10540

10641
## parseQuery
10742

10843
Transforms a queryString into a [LocationQuery](./vue-router-typealias#locationquery) object. Accept both, a version with the leading `?` and without Should work as URLSearchParams
10944

11045
**Signature:**
46+
11147
```typescript
112-
export declare function parseQuery(search: string): LocationQuery;
48+
export declare function parseQuery(search: string): LocationQuery
11349
```
11450

11551
### Parameters
11652

117-
| Parameter | Type | Description |
118-
| --- | --- | --- |
119-
| search | string | search string to parse |
53+
| Parameter | Type | Description |
54+
| --------- | ------ | ---------------------- |
55+
| search | string | search string to parse |
12056

12157
### Returns
12258

123-
a query object
59+
a query object
12460

12561
## stringifyQuery
12662

12763
Stringifies a [LocationQueryRaw](./vue-router-typealias#locationqueryraw) object. Like `URLSearchParams`, it doesn't prepend a `?`
12864

12965
**Signature:**
66+
13067
```typescript
131-
export declare function stringifyQuery(query: LocationQueryRaw): string;
68+
export declare function stringifyQuery(query: LocationQueryRaw): string
13269
```
13370

13471
### Parameters
13572

136-
| Parameter | Type | Description |
137-
| --- | --- | --- |
138-
| query | LocationQueryRaw | query object to stringify |
73+
| Parameter | Type | Description |
74+
| --------- | ---------------- | ------------------------- |
75+
| query | LocationQueryRaw | query object to stringify |
13976

14077
### Returns
14178

142-
string version of the query without the leading `?`
79+
string version of the query without the leading `?`
14380

14481
## useLink
14582

14683
## useRoute
14784

14885
## useRouter
149-

src/history/hash.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { createWebHistory } from './html5'
33
import { warn } from '../warning'
44

55
/**
6-
* Creates a hash history.
6+
* Creates a hash history. Useful for web applications with no host (e.g.
7+
* `file://`) or when configuring a server to handle any URL.
78
*
89
* @param base - optional base to provide. Defaults to `___location.pathname` or
910
* `/` if at root. If there is a `base` tag in the `head`, its value will be

src/history/html5.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ function useHistoryStateNavigation(base: string) {
271271
}
272272
}
273273

274+
/**
275+
* Creates an HTML5 history. Most common history for single page applications.
276+
*
277+
* @param base
278+
*/
274279
export function createWebHistory(base?: string): RouterHistory {
275280
base = normalizeBase(base)
276281

src/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export interface Router {
318318
}
319319

320320
/**
321-
* Create a Router instance that can be used on a Vue app.
321+
* Creates a Router instance that can be used by a Vue app.
322322
*
323323
* @param options - {@link RouterOptions}
324324
*/

0 commit comments

Comments
 (0)