navigo

WebJar for navigo

License

License

MIT
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

navigo
Last Version

Last Version

7.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

navigo
WebJar for navigo
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/krasimir/navigo

Download navigo

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/navigo/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>navigo</artifactId>
    <version>7.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/navigo/
implementation 'org.webjars.bower:navigo:7.0.0'
// https://jarcasting.com/artifacts/org.webjars.bower/navigo/
implementation ("org.webjars.bower:navigo:7.0.0")
'org.webjars.bower:navigo:jar:7.0.0'
<dependency org="org.webjars.bower" name="navigo" rev="7.0.0">
  <artifact name="navigo" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='navigo', version='7.0.0')
)
libraryDependencies += "org.webjars.bower" % "navigo" % "7.0.0"
[org.webjars.bower/navigo "7.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Navigo

A simple dependency-free minimalistic JavaScript router

npm downloads size

Selling points

  • Dependency free
  • ~10KB minified, ~4KB gzipped
  • Based on History API so it does update the URL of the page
  • Supports hash based routing too
  • Simple mapping of route to a function call
  • Parameterized routes
  • Navigating between routes
  • Hooks (before, after, leave, already)
  • Not-found and default handler
  • Easy integration with HTML links via data-navigo HTML attribute

Installation

Drop the following into your page:

<script src="//unpkg.com/navigo"></script>

or via npm/yarn:

> npm install navigo --save
> yarn add navigo -S

Quick start

const router = new Navigo('/');

The constructor of the library accepts a single argument - the root path of your app. If you host your project at https://site.com/my/awesome/app, your root path is /my/awesome/app. Then you have to define your routes.

router.on('/products/list', function () {
  // do something
});

At the end you have to trigger the resolving logic:

router.resolve();

After that when you need a page change call the navigate method. This one changes the URL and (by default) triggers resolve.

router.navigate('/about');

Add data-navigo attribute to your page links and they'll be transformed into navigate callers.

<a href="/about/contacts" data-navigo>Contacts</a>

Checkout the online playground to see it in action.

Development

> yarn dev

Building

> yarn build

Tests

> yarn test
> yarn test-watch

MISC

Versions

Version
7.0.0