Router

Router class.

new Router($0: Object, options: Object)
License: {@link https://opensource.org/licenses/MIT|MIT}
Author: Patrick Heng & Fabien Motte <hengpatrick.pro@gmail.com / contact@fabienmotte.com>
Parameters
$0 (Object = {})
Name Description
$0.routes any (default [])
$0.components any (default {})
$0.basePath any (default '/')
$0.mode any (default Router.BROWSER_MODE)
$0.locale any (default '')
$0.preRendered any (default false)
$0.restoreScroll any (default false)
$0.debugMode any (default false)
options (Object = {}) Options.
Example
const routes = [{
  name: 'home',
  callback: route => { },
  path: '/'
}]
const router = new Router({ routes })
Static Members
BROWSER_MODE
HASH_MODE
MEMORY_MODE
PUSH_ACTION
REPLACE_ACTION
POP_ACTION
Instance Members
mount(el)
navigate(options)
go(n)
back()
forward()
replace(options)
beforeEach(from, to, next)
afterEach(from, to, next)

startsWith

Starts with.

startsWith
Parameters
str (String) String.
prefix (String) Prefix.
Returns
Boolean: True if given string starts with given prefix, else otherwise.

endsWith

Ends with.

endsWith
Parameters
str (String) String.
suffix (String) Suffix.
Returns
Boolean: True if given string ends with given suffix, else otherwise.

addLeadingSlash

Add leading slash.

addLeadingSlash
Parameters
str (String) String.
Returns
String: String with a leading slash.

stripLeadingSlash

Strip leading slash.

stripLeadingSlash
Parameters
str (String) String.
Returns
String: String without leading slash.

stripTrailingSlash

Strip trailing slash.

stripTrailingSlash
Parameters
str (String) String.
Returns
String: String without trailing slash.

stripSlashes

Strip slashes.

stripSlashes
Parameters
str (String) String.
Returns
String: String without slashes.

isString

Is string.

isString
Parameters
val (any) String.
Returns
Boolean: True if it is a string, false otherwise.

getHashPath

Get hash from a path.

getHashPath
Parameters
href (String = window.location.href) Href.
Returns
String: Hash extracted.

generateSpaces

Generate spaces.

generateSpaces
Parameters
str (String) String.
Returns
String: Spaces corresponding to given string length.

supportsBrowserHistory

Check browser history support.

supportsBrowserHistory
Returns
Boolean: True if browser history is supported, false otherwise.

supportsScrollRestoration

Check scroll restoration support.

supportsScrollRestoration
Returns
Boolean: True if scroll restoration is supported, false otherwise.