sham-ui-router v6.1.0
sham-ui-router
Router for sham-ui
Install
# npm
npm install sham-ui-router
# yarn
yarn add sham-ui-router
API
Table of Contents
- LinkToOptions
- LinkTo
- ActivePageContainer
- ParamsBuilder
- path
- HrefTo
- lazyPage
- Router
- routerStorage
- RouterStorage
LinkToOptions
Options for LinkTo
Type: Object
Properties
path
string Name of page for link. Default ''params
Object Params of page for link. Default {}text
string Text for link. Default ''useActiveClass
boolean Use activeClass options for active page link. Default falseactiveClass
string Class name for active link. Default 'active'
LinkTo
Component for link to page
Properties
options
LinkToOptions
ActivePageContainer
Component-container for page
Examples
{% import ActivePageContainer from 'sham-ui-router/active-page-container' %}
...
<ActivePageContainer/>
...
ParamsBuilder
Helper for build params for href-to directive
Type: Object
Examples
{% import path from 'sham-ui-router/params' %}
...
<a :hrefto={{path("foo").param("id", 2)}} class="custom-class-1 custom-class-2">
Foo
</a>
...
param
Add param for page
Parameters
name
string Param namevalue
any Param value
Returns ParamsBuilder
_params
Set params
Parameters
value
Object
Returns ParamsBuilder
_useActiveClass
Use active class
Returns ParamsBuilder
_activeClass
Set active class
Parameters
activeClass
string
Returns ParamsBuilder
path
Create new ParamsBuilder
Parameters
path
string Name of destination page
Returns ParamsBuilder
HrefTo
Directive for links
Parameters
component
Examples
...
<a :hrefto={{ {"path": "foo", "params": params} }} class="custom-class-1 custom-class-2">
Foo
</a>
....
lazyPage
Hook for process lazy page after loader finish. Can override with DI.bind( 'router:lazy-page' )
Parameters
pageComponent
Class<Component>
Returns Class<Component>
Router
Router service
Parameters
DI
Object App DI containerroot
(string | null) Root URL (optional, defaultnull
)useHash
boolean Use hash symbol as delimiter (optional, defaultfalse
)hash
string Hash symbol (use useHash=true) (optional, default'#'
)
Examples
import FooPage from '../components/FooPage.sht';
import BarPage from '../components/BarPage.sht';
import Router from 'sham-ui-router';
const router = new Router();
router
.bindPage(
'/foo', // URL
'foo', // Name
FooPage, // Component class
{ componentOption: 1 } // Component options
)
.bindLazyPage( '/bar/:some_param/detail', 'bar', () => import( '../src/components/BarPage' ), {} )
.resolve();
bindPage
Bind page component & url
Parameters
url
string Url for pagename
string Page name*pageComponent
Class<Component> Component for pagecomponentOptions
Object Options for component
Returns Router
bindLazyPage
Bind lazy loaded page component & url
Parameters
url
string Url for pagename
string Page nameloader
Function Loader for page componentcomponentOptions
Object Options for component
Returns Router
navigateToRoute
Go to route by name
Parameters
resolve
Resolve current url & run router
notFound
Not found handler
navigate
Changing the page
Parameters
url
string Destination url
hooks
Hooks
Parameters
hooks
Object Object with hooks
generate
Generate url for page
Parameters
Examples
router
.bindPage( '/trip/:tripId/edit', 'trip.edit', PageComponent, {} )
.bindPage( '/trip/save', 'trip.save', PageComponent, {} )
.bindPage( '/trip/:action/:tripId', 'trip.action', PageComponent, {} );
console.log(router.generate('trip.edit', { tripId: 42 })); // --> /trip/42/edit
console.log(router.generate('trip.action', { tripId: 42, action: 'save' })); // --> /trip/save/42
console.log(router.generate('trip.save')); // --> /trip/save
routerStorage
Type: RouterStorage
RouterStorage
Data storage for router service
Type: Object
Properties
url
string Current page urlname
string Current page nameparams
Object Current page paramsquery
string Current page queryactivePageComponent
Class<Component> Current page component classactivePageOptions
Object Options for current page componentpageLoaded
boolean Current page component loaded (@see Router.bindLazyPage)
8 months ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago