Skip to content

Commit

Permalink
Add navigateToRoute method to Router service
Browse files Browse the repository at this point in the history
  • Loading branch information
shamcode committed Oct 27, 2022
1 parent cd0745c commit 25b1ac0
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 74 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 6.0.0-alpha.3
* Add `navigateToRoute` method to `Router` service

## 6.0.0-alpha.2
* Add call context `resetOwner` on remove page component
* Update dependencies
Expand Down
157 changes: 86 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ yarn add sham-ui-router

#### Table of Contents

- [ParamsBuilder](#paramsbuilder)
- [LinkToOptions](#linktooptions)
- [Properties](#properties)
- [LinkTo](#linkto)
- [Properties](#properties-1)
- [ActivePageContainer](#activepagecontainer)
- [Examples](#examples)
- [ParamsBuilder](#paramsbuilder)
- [Examples](#examples-1)
- [param](#param)
- [Parameters](#parameters)
- [\_params](#_params)
Expand All @@ -35,36 +41,68 @@ yarn add sham-ui-router
- [Parameters](#parameters-2)
- [path](#path)
- [Parameters](#parameters-3)
- [ActivePageContainer](#activepagecontainer)
- [Examples](#examples-1)
- [LinkTo](#linkto)
- [Properties](#properties)
- [LinkToOptions](#linktooptions)
- [Properties](#properties-1)
- [HrefTo](#hrefto)
- [Examples](#examples-2)
- [pageComponent](#pagecomponent)
- [Parameters](#parameters-4)
- [Router](#router)
- [Examples](#examples-2)
- [lazyPage](#lazypage)
- [Parameters](#parameters-5)
- [Router](#router)
- [Parameters](#parameters-6)
- [Examples](#examples-3)
- [storage](#storage)
- [bindPage](#bindpage)
- [Parameters](#parameters-6)
- [bindLazyPage](#bindlazypage)
- [Parameters](#parameters-7)
- [navigate](#navigate)
- [bindLazyPage](#bindlazypage)
- [Parameters](#parameters-8)
- [hooks](#hooks)
- [navigateToRoute](#navigatetoroute)
- [Parameters](#parameters-9)
- [notFound](#notfound)
- [resolve](#resolve)
- [generate](#generate)
- [notFound](#notfound)
- [navigate](#navigate)
- [Parameters](#parameters-10)
- [hooks](#hooks)
- [Parameters](#parameters-11)
- [generate](#generate)
- [Parameters](#parameters-12)
- [Examples](#examples-4)
- [RouterStorage](#routerstorage)
- [routerStorage](#routerstorage)
- [RouterStorage](#routerstorage-1)
- [Properties](#properties-2)

### LinkToOptions

Options for LinkTo

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

#### Properties

- `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of page for link. Default ''
- `params` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Params of page for link. Default {}
- `text` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Text for link. Default ''
- `useActiveClass` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Use activeClass options for active page link. Default false
- `activeClass` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Class name for active link. Default 'active'

### LinkTo

Component for link to page

#### Properties

- `options` **[LinkToOptions](#linktooptions)**

### ActivePageContainer

Component-container for page

#### Examples

```javascript
{% import ActivePageContainer from 'sham-ui-router/active-page-container' %}
...
<ActivePageContainer/>
...
```
### ParamsBuilder
Helper for build params for href-to directive
Expand Down Expand Up @@ -129,47 +167,14 @@ Create new ParamsBuilder
Returns **[ParamsBuilder](#paramsbuilder)**
### ActivePageContainer
**Extends Component**
Component-container for page
#### Examples
```javascript
{% import ActivePageContainer from 'sham-ui-router/active-page-container' %}
...
<ActivePageContainer/>
...
```
### LinkTo
Component for link to page
#### Properties
- `options` **[LinkToOptions](#linktooptions)**
### LinkToOptions
Options for LinkTo
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
#### Properties
- `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of page for link. Default ''
- `params` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Params of page for link. Default {}
- `text` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Text for link. Default ''
- `useActiveClass` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Use activeClass options for active page link. Default false
- `activeClass` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Class name for active link. Default 'active'
### HrefTo
Directive for links
#### Parameters
- `component`
#### Examples
```javascript
Expand All @@ -180,7 +185,7 @@ Directive for links
....
```
### pageComponent
### lazyPage
Hook for process lazy page after loader finish. Can override with DI.bind( 'router:lazy-page' )
Expand All @@ -196,6 +201,7 @@ Router service
#### Parameters
- `DI` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** App DI container
- `root` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** Root URL (optional, default `null`)
- `useHash` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Use hash symbol as delimiter (optional, default `false`)
- `hash` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Hash symbol (use useHash=true) (optional, default `'#'`)
Expand All @@ -219,10 +225,6 @@ router
.resolve();
```
#### storage
Type: [RouterStorage](#routerstorage)
#### bindPage
Bind page component & url
Expand All @@ -243,12 +245,31 @@ Bind lazy loaded page component & url
##### Parameters
- `url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Url for page
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Page name\*
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Page name
- `loader` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Loader for page component
- `componentOptions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options for component
Returns **[Router](#router)**
#### navigateToRoute
Go to route by name
##### Parameters
- `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Page name
- `params` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Optional page params
#### resolve
Resolve current url & run router
#### notFound
- **See: <https://github.com/krasimir/navigo#not-found-handler>**
Not found handler
#### navigate
Changing the page
Expand All @@ -267,16 +288,6 @@ Hooks
- `hooks` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Object with hooks
#### notFound
- **See: <https://github.com/krasimir/navigo#not-found-handler>**
Not found handler
#### resolve
Resolve current url & run router
#### generate
- **See: <https://github.com/krasimir/navigo#named-routes>**
Expand All @@ -300,6 +311,10 @@ console.log(router.generate('trip.action', { tripId: 42, action: 'save' })); //
console.log(router.generate('trip.save')); // --> /trip/save
```
### routerStorage
Type: [RouterStorage](#routerstorage)
### RouterStorage
- **See: <https://github.com/sham-ui/sham-ui-data-storage>**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "lib/index.js",
"module": "module/index.js",
"author": "Eugeny Burnashov <[email protected]>",
"version": "6.0.0-alpha.2",
"version": "6.0.0-alpha.3",
"scripts": {
"start": "MACRO_REF_REPLACE=enabled rollup -w -c ./demo-app/rollup.config.js",
"test:clear-cache": "jest --clearCache",
Expand All @@ -13,7 +13,7 @@
"build": "rollup -c",
"size": "MACRO_REF_REPLACE=uniq yarn build && size-limit",
"prepublish": "yarn size && yarn build",
"doc:generate": "documentation readme src/component.js --section=API",
"doc:generate": "documentation readme src/** --section=API",
"doc:lint": "documentation lint src/**"
},
"devDependencies": {
Expand Down
13 changes: 12 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default class Router {
/**
* Bind lazy loaded page component & url
* @param {string} url Url for page
* @param {string} name Page name*
* @param {string} name Page name
* @param {Function} loader Loader for page component
* @param {Object} componentOptions Options for component
* @return {Router}
Expand All @@ -196,4 +196,15 @@ export default class Router {
}, componentOptions ) );
return this;
}

/**
* Go to route by name
* @param {string} name Page name
* @param {Object} [params] Optional page params
*/
navigateToRoute( name, params ) {
this.navigate(
this.generate( name, params )
);
}
}

0 comments on commit 25b1ac0

Please sign in to comment.