You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: addons/van_cone/API_REFERENCE.md
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Van Cone
1
+
# Van Cone
2
2
3
3
See [README.md](./README.md) for installation and overview.
4
4
@@ -13,11 +13,11 @@ See [README.md](./README.md) for installation and overview.
13
13
14
14
-`routerElement` - (required) the root DOM element element that holds the app (element defined by active route)
15
15
16
-
-`routes` - (required) an array of [routes](#routes)
16
+
-`routes` - (required) an array of [`routes`](#routes)
17
17
18
-
-`defaultNavState` - (optional) the default navigation state, any type allowed by [history.pushState](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
18
+
-`defaultNavState` - (optional) the default navigation state, any type allowed by [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
19
19
20
-
-[routerConfig](#constructorrouterconfig) = (optional) - configure `prefix` to prepend to each url, or `backendPrefix` if different than frontend.
20
+
-[`routerConfig`](#constructorrouterconfig) = (optional) - configure `prefix` to prepend to each url, or `backendPrefix` if different than frontend.
21
21
22
22
**return**
23
23
@@ -27,7 +27,7 @@ An object with the following items is returned:
27
27
28
28
-`currentPage` - a `van.state` object representing the `name` value of the active route
29
29
30
-
-`router` - the [router](#router) object for the application
30
+
-`router` - the [`router`](#router) object for the application
31
31
32
32
-`navState` - a `van.state` object representing the current [`window.history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state)
33
33
@@ -54,7 +54,7 @@ A list of objects defining each route. Each route object has the following prope
54
54
55
55
**`callable`** (required) a callback that either returns an element to put on the DOM or another callable that returns this element (for more complex apps requiring imports). The callback is passed 2 arguments, an object representing the params parsed from the URL and another representing parsed query string params.
56
56
57
-
**`backend`** (optional) provide this value when data is fetched from a different endpoint on the backend than on the frontend. See [router.backendUrl](#backendurlroutename-params---query) for more.
57
+
**`backend`** (optional) provide this value when data is fetched from a different endpoint on the backend than on the frontend. See [`router.backendUrl`](#backendurlroutename-params---query) for more.
58
58
59
59
**`title`** (optional) if provided the title of the page will change to this when this route is active.
60
60
@@ -92,7 +92,7 @@ const routes = [
92
92
```
93
93
94
94
### different backend endpoint
95
-
When data is fetched from a different endpoint provide a backend path as follows. See [router.backendUrl](#backendurlroutename-params---query) for information on generating a backend url for fetching data.
95
+
When data is fetched from a different endpoint provide a backend path as follows. See [`router.backendUrl`](#backendurlroutename-params---query) for information on generating a backend url for fetching data.
The `routerConfig` object is used to construct a new router, it is an object with two optional keys `prefix` and `backendPrefix`. If `routerConfig` is not provided or either key is not provided they will default to an empty string.
206
+
The `routerConfig` object is used to construct a new router, it is an object with two optional keys `prefix` and `backendPrefix`. If `routerConfig` is not provided or either key is not provided they will default to an empty string.
207
207
208
-
`prefix` will be prepended to front end URLs, the ones shown in the browser and matched when navigating to different pages. See [router.navUrl](#navurlroutename-params---query) for more.
208
+
`prefix` will be prepended to front end URLs, the ones shown in the browser and matched when navigating to different pages. See [`router.navUrl`](#navurlroutename-params---query) for more.
209
209
210
-
The `backendPrefix` is useful for when the backend is at a different host or has a different prefix than the front end. It is only used as a utility to generate URLs for fetching data, it is ignored for route matching and page navigation. See [router.backendUrl](#backendurlroutename-params---query) for more.
210
+
The `backendPrefix` is useful for when the backend is at a different host or has a different prefix than the front end. It is only used as a utility to generate URLs for fetching data, it is ignored for route matching and page navigation. See [`router.backendUrl`](#backendurlroutename-params---query) for more.
211
211
212
212
#### `navUrl(routeName, params = {}, query = {})`
213
-
Return a string representing a url for the route with name `routeName`, and optionally form url params with the `params` argument or query params with the `query` argument. The return can be used with [navigate](#navigateurl-context) or any other place a url string is needed. If `prefix` was included with [routerConfig](#constructorrouterconfig) it will be prepended to the url.
213
+
Return a string representing a url for the route with name `routeName`, and optionally form url params with the `params` argument or query params with the `query` argument. The return can be used with [`navigate`](#navigateurl-context) or any other place a url string is needed. If `prefix` was included with [`routerConfig`](#constructorrouterconfig) it will be prepended to the url.
214
214
215
-
**Note: to access this function from the return value of [createCone](#createconerouterelement-routes-defaultnavstate) call `router.navUrl`**
215
+
**Note: to access this function from the return value of [`createCone`](#createconerouterelement-routes-defaultnavstate) call `router.navUrl`**
Return a string backend url for the route with name `routeName`, and optionally form url params with the `params` argument or query params with the `query` argument. The return can be used for fetching data. If `backendPrefix` was included with [routerConfig](#constructorrouterconfig) it will be prepended to the url.
234
+
Return a string backend url for the route with name `routeName`, and optionally form url params with the `params` argument or query params with the `query` argument. The return can be used for fetching data. If `backendPrefix` was included with [`routerConfig`](#constructorrouterconfig) it will be prepended to the url.
235
235
236
-
**Note: to access this function from the return value of [createCone](#createconerouterelement-routes-defaultnavstate) call `router.backendUrl`**
236
+
**Note: to access this function from the return value of [`createCone`](#createconerouterelement-routes-defaultnavstate) call `router.backendUrl`**
237
237
238
-
The following [routerConfig](#constructorrouterconfig) and [routes](#routes):
238
+
The following [`routerConfig`](#constructorrouterconfig) and [`routes`](#routes):
Programmatically navigate to `url`. Optionally pass `context` which can be and data to the resolved router component.
275
275
276
-
You can use [router.navUrl](#navigateurl-context) to generate urls from named routes with url and query params.
276
+
You can use [`router.navUrl`](#navigateurl-context) to generate urls from named routes with url and query params.
277
277
278
278
## `pushHistory(url)`
279
279
Push `url` to browser history and update address bar only, do not modify DOM.
280
280
281
-
You can use [router.navUrl](#navigateurl-context) to generate urls from named routes with url and query params.
281
+
You can use [`router.navUrl`](#navigateurl-context) to generate urls from named routes with url and query params.
282
282
283
283
## `handleNav(event, context)`
284
284
An event wrapper for [`navigate`](#navigateurl-context) to be used with an on click action. `handleNav` will call `event.preventDefault` and then call [`navigate`](#navigateurl-context) with `event.target.href`.
285
285
286
-
It is used internally to create the [navLink](#navlinkprops-children) component.
286
+
It is used internally to create the [`navLink`](#navlinkprops-children) component.
287
287
288
288
Optionally pass `context` which can be and data to the resolved router component.
289
289
290
-
You can use [router.navUrl](#navurlroutename-params---query) to generate urls from named routes and formatting url/query params.
290
+
You can use [`router.navUrl`](#navurlroutename-params---query) to generate urls from named routes and formatting url/query params.
291
291
292
292
## `isCurrentPage(pageName)`
293
293
Returns a `van.derive` object with a boolean that is true when `pageName` is the active route
@@ -296,7 +296,7 @@ if (isCurrentPage("home").val) console.log("we're home!")
296
296
```
297
297
298
298
## `navLink(props, ...children)`
299
-
Uses [router.navUrl](#navurlroutename-params---query) to return a link element using `van.tags.a` by passing `props` and `children` to the underling call to `van.tags.a` with a few modifications to the resulting `a` element that adds programmatic navigation and dynamic styling for when it is the active route. URLs are generated using the name of the route, and optional url and query string params.
299
+
Uses [`router.navUrl`](#navurlroutename-params---query) to return a link element using `van.tags.a` by passing `props` and `children` to the underling call to `van.tags.a` with a few modifications to the resulting `a` element that adds programmatic navigation and dynamic styling for when it is the active route. URLs are generated using the name of the route, and optional url and query string params.
300
300
301
301
### examples
302
302
A basic call to the route named `home` with the inner text for the a tag `Home`. This is the bare minimum required for `navLink`.
@@ -365,7 +365,7 @@ The following have default values:
365
365
*`props.class` (default: `router-link`)
366
366
367
367
The following are hardcoded and cannot be changed:
368
-
*`props.href` is set by a call to [router.navUrl](#navurlroutename-params---query) with `props.name`, `props.params` and `props.query`
368
+
*`props.href` is set by a call to [`router.navUrl`](#navurlroutename-params---query) with `props.name`, `props.params` and `props.query`
369
369
*`props.role` is set to `link`
370
370
*`props.onClick` is set to [`handleNav`](#handlenavevent-context)
Copy file name to clipboardExpand all lines: addons/van_cone/README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ See the [API Reference](./API_REFERENCE.md) for full documentation.
94
94
95
95
96
96
# Support, issues, and suggestions
97
-
Open an issue or discussion either on the [offical repo](https://github.com/vanjs-org/van) or [my fork](https://github.com/b-rad-c/van/tree/main). Make sure to tag my username: [@b-rad-c](https://github.com/b-rad-c).
97
+
Open an issue or discussion either on the [official repo](https://github.com/vanjs-org/van) or [my fork](https://github.com/b-rad-c/van/tree/main). Make sure to tag my username: [@b-rad-c](https://github.com/b-rad-c).
98
98
99
99
# Contributing
100
100
Got some skills? Want to contribute? Send a pull request!
@@ -105,10 +105,10 @@ I, [@b-rad-c](https://github.com/b-rad-c) am the maintainer of this project howe
105
105
Some things I'm interested in.
106
106
* unittests
107
107
* convert to TypeScript
108
-
*stabilze API to come out of beta - comments or suggestions to the API are welcome.
108
+
*stabilize API to come out of beta - comments or suggestions to the API are welcome.
109
109
110
110
# The Name
111
111
Van Cone is an addon for VanJS which is short for **Van**illa **J**ava**S**cript, and makes a callout to vanilla ice cream in its logo. Van Cone provides the cone that is needed to support the ice cream. VanJS provides reactivity and UI components, Van Cone provides routing, history and navigation components, together they're everything you need for a lightweight SPA experience!
112
112
113
113
# Credit
114
-
router based on [minimal router](https://github.com/jmhdez/minimal-router) (no longer maintained)
114
+
Router based on [minimal router](https://github.com/jmhdez/minimal-router) (no longer maintained).
0 commit comments