1.8.2 • Published 7 years ago

mobx-little-router v1.8.2

Weekly downloads
35
License
MIT
Repository
github
Last release
7 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

7 years ago

1.8.1

7 years ago

2.0.0-20

7 years ago

2.0.0-19

7 years ago

2.0.0-18

7 years ago

2.0.0-17

7 years ago

2.0.0-16

7 years ago

2.0.0-15

7 years ago

2.0.0-14

7 years ago

2.0.0-10

7 years ago

2.0.0-9

7 years ago

2.0.0-5

7 years ago

2.0.0-4

7 years ago

2.0.0-3

7 years ago

2.0.0-2

7 years ago

2.0.0-1

7 years ago

2.0.0-0

7 years ago

1.8.0

7 years ago

1.7.4

7 years ago

1.7.3

7 years ago

1.7.2

7 years ago

1.7.0-2

8 years ago

1.7.0-1

8 years ago

1.7.0-0

8 years ago

1.6.10

8 years ago

1.6.8

8 years ago

1.6.7

8 years ago

1.6.6

8 years ago

1.6.5

8 years ago

1.6.4

8 years ago

1.6.3

8 years ago

1.6.2

8 years ago

1.6.1

8 years ago

1.6.0

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.5.0-19

8 years ago

1.5.0-18

8 years ago

1.5.0-17

8 years ago

1.5.0-15

8 years ago

1.5.0-13

8 years ago

1.5.0-8

8 years ago

1.5.0-7

8 years ago

1.5.0-6

8 years ago

1.5.0-5

8 years ago

1.5.0-4

8 years ago

1.5.0-3

8 years ago

1.5.0-2

8 years ago

1.5.0-1

8 years ago

1.5.0-0

8 years ago

1.4.5

8 years ago

1.4.4

8 years ago

1.4.3

8 years ago

1.4.2

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

1.0.0-rc.9.1.0

8 years ago

1.0.0-beta.1.4

8 years ago

1.0.0-beta.1.3

8 years ago

1.0.0-beta.1.2

8 years ago

1.0.0-beta.1.1

8 years ago

1.0.0-beta.1.0

8 years ago

1.0.0-beta.1

8 years ago

1.0.0-rc27.0

8 years ago

1.0.0-rc26.0

8 years ago

1.0.0-rc25.0

8 years ago

1.0.0-rc24.0

8 years ago

1.0.0-rc23.0

8 years ago

1.0.0-rc22.0

8 years ago

1.0.0-rc21.0

8 years ago

1.0.0-rc20.0

8 years ago

1.0.0-rc19.0

8 years ago

1.0.0-rc18.0

8 years ago

1.0.0-rc17.0

8 years ago

1.0.0-rc16.0

8 years ago

1.0.0-rc15.0

8 years ago

1.0.0-rc14.0

8 years ago

1.0.0-13.0

8 years ago

1.0.0-rc12.0

8 years ago

1.0.0-rc11.0

8 years ago

1.0.0-rc10.0

8 years ago

1.0.0-rc9.0

8 years ago

1.0.0-rc8.0

8 years ago

1.0.0-rc7.0.0

8 years ago

1.0.0-rc2

8 years ago

1.0.0-rc1

8 years ago

1.0.0-r1

8 years ago

0.9.5

8 years ago

0.9.4

8 years ago