1.8.2 • Published 6 years ago

mobx-little-router v1.8.2

Weekly downloads
35
License
MIT
Repository
github
Last release
6 years ago

mobx-little-router

This package provides the core functionality of the MobX little router.

Getting Started

Import the install function from package, along with your chosen history creator from history package.

import { install } from 'mobx-little-router'
import { createMemoryHistory } from 'history'

const ROUTES = [{ path: ':whatever' }]

const router = install({
  history: createMemoryHistory(),
  routes: ROUTES
})

Then run router.start(...) which takes in a callback when initialization finishes.

import { autorun } from 'mobx'

router.start(() => {
  autorun(() => console.log(`path = ${router.store.location.pathname}`))

  router.push('/a') // Prints "path = /a/"
  router.push('/b') // Prints "path = /b/"
  router.push('/c') // Prints "path = /c/"

  router.push('/not/found') // Navigation aborts since path cannot be matched from config.
})

Install options

The install function takes the following options:

  • history - The history object created from history.
  • getContext - A function that returns a context object that is accessible from each route. This is useful for sharing MobX stores or other injectable objects.
  • middleware - Custom router middleware for your application.
  • routes - A list of initial route configuration of type Config[], where

    type Config = {
      path: string,
    
      // Static child routes.
      children?: Config[],
    
      // Dynamic child routes
      loadChildren?: () => Promise<Config[]>,
    
      // Guard functions that can block a route from activating or deactivating.
      canActivate?: (route: Route<*, *>) => boolean | Promise<void>,
      canDeactivate?: (route: Route<*, *>) => boolean | Promise<void>,
    
      // Called for each activation or query/param changes to the route.
      // Used for resolving effects.
      willResolve?: (route: Route<*, *>) => Promise<void>,
    
      onTransition?: (evt: TransitionEvent) => Promise<void>
    }

    For more type information, check out the routing/types.js file.

Documentation

1.8.2

6 years ago

1.8.1

6 years ago

2.0.0-20

6 years ago

2.0.0-19

6 years ago

2.0.0-18

6 years ago

2.0.0-17

6 years ago

2.0.0-16

6 years ago

2.0.0-15

6 years ago

2.0.0-14

6 years ago

2.0.0-10

6 years ago

2.0.0-9

6 years ago

2.0.0-5

6 years ago

2.0.0-4

6 years ago

2.0.0-3

6 years ago

2.0.0-2

6 years ago

2.0.0-1

6 years ago

2.0.0-0

6 years ago

1.8.0

6 years ago

1.7.4

6 years ago

1.7.3

6 years ago

1.7.2

6 years ago

1.7.0-2

6 years ago

1.7.0-1

6 years ago

1.7.0-0

6 years ago

1.6.10

6 years ago

1.6.8

6 years ago

1.6.7

6 years ago

1.6.6

6 years ago

1.6.5

6 years ago

1.6.4

6 years ago

1.6.3

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.5.0-19

7 years ago

1.5.0-18

7 years ago

1.5.0-17

7 years ago

1.5.0-15

7 years ago

1.5.0-13

7 years ago

1.5.0-8

7 years ago

1.5.0-7

7 years ago

1.5.0-6

7 years ago

1.5.0-5

7 years ago

1.5.0-4

7 years ago

1.5.0-3

7 years ago

1.5.0-2

7 years ago

1.5.0-1

7 years ago

1.5.0-0

7 years ago

1.4.5

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

1.0.0-rc.9.1.0

7 years ago

1.0.0-beta.1.4

7 years ago

1.0.0-beta.1.3

7 years ago

1.0.0-beta.1.2

7 years ago

1.0.0-beta.1.1

7 years ago

1.0.0-beta.1.0

7 years ago

1.0.0-beta.1

7 years ago

1.0.0-rc27.0

7 years ago

1.0.0-rc26.0

7 years ago

1.0.0-rc25.0

7 years ago

1.0.0-rc24.0

7 years ago

1.0.0-rc23.0

7 years ago

1.0.0-rc22.0

7 years ago

1.0.0-rc21.0

7 years ago

1.0.0-rc20.0

7 years ago

1.0.0-rc19.0

7 years ago

1.0.0-rc18.0

7 years ago

1.0.0-rc17.0

7 years ago

1.0.0-rc16.0

7 years ago

1.0.0-rc15.0

7 years ago

1.0.0-rc14.0

7 years ago

1.0.0-13.0

7 years ago

1.0.0-rc12.0

7 years ago

1.0.0-rc11.0

7 years ago

1.0.0-rc10.0

7 years ago

1.0.0-rc9.0

7 years ago

1.0.0-rc8.0

7 years ago

1.0.0-rc7.0.0

7 years ago

1.0.0-rc2

7 years ago

1.0.0-rc1

7 years ago

1.0.0-r1

7 years ago

0.9.5

7 years ago

0.9.4

7 years ago