Router for sham-ui
# npm
npm install sham-ui-router
# yarn
yarn add sham-ui-router
- LinkToOptions
- LinkTo
- ActivePageContainer
- ParamsBuilder
- path
- HrefTo
- lazyPage
- Router
- routerStorage
- RouterStorage
Options for LinkTo
Type: Object
-
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 false -
activeClass
string Class name for active link. Default 'active'
Component for link to page
-
options
LinkToOptions
Component-container for page
{% import ActivePageContainer from 'sham-ui-router/active-page-container' %}
...
<ActivePageContainer/>
...
Helper for build params for href-to directive
Type: Object
{% import path from 'sham-ui-router/params' %}
...
<a :hrefto={{path("foo").param("id", 2)}} class="custom-class-1 custom-class-2">
Foo
</a>
...
Add param for page
-
name
string Param name -
value
any Param value
Returns ParamsBuilder
Set params
-
value
Object
Returns ParamsBuilder
Use active class
Returns ParamsBuilder
Set active class
-
activeClass
string
Returns ParamsBuilder
Create new ParamsBuilder
-
path
string Name of destination page
Returns ParamsBuilder
Directive for links
component
...
<a :hrefto={{ {"path": "foo", "params": params} }} class="custom-class-1 custom-class-2">
Foo
</a>
....
Hook for process lazy page after loader finish. Can override with DI.bind( 'router:lazy-page' )
-
pageComponent
Class<Component>
Returns Class<Component>
Router service
-
DI
Object App DI container -
root
(string | null) Root URL (optional, defaultnull
) -
useHash
boolean Use hash symbol as delimiter (optional, defaultfalse
) -
hash
string Hash symbol (use useHash=true) (optional, default'#'
)
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();
Bind page component & url
-
url
string Url for page -
name
string Page name* -
pageComponent
Class<Component> Component for page -
componentOptions
Object Options for component
Returns Router
Bind lazy loaded page component & url
-
url
string Url for page -
name
string Page name -
loader
Function Loader for page component -
componentOptions
Object Options for component
Returns Router
Go to route by name
Resolve current url & run router
Not found handler
Changing the page
-
url
string Destination url
Hooks
-
hooks
Object Object with hooks
Generate url for page
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
Type: RouterStorage
Data storage for router service
Type: Object
-
url
string Current page url -
name
string Current page name -
params
Object Current page params -
query
string Current page query -
activePageComponent
Class<Component> Current page component class -
activePageOptions
Object Options for current page component -
pageLoaded
boolean Current page component loaded (@see Router.bindLazyPage)