vuenit.router() | vuenit.mockRouter()

Creates a mock router that can be injected into a component. It mimics the vue-router api without its entire functionality.

The router can be created in a number of ways:

// creates a router with a default route of { path : '/' }
var {$route, $router} = mockRouter();
// creates a router with a single route of { path : '/users' }
var {$route, $router} = mockRouter('/users');
// creates a router with two routes: [ { path : '/' }, { path : '/users' }]
var {$route, $router} = mockRouter(['/', '/users']);
// creates the same router as above
var {$route, $router} = mockRouter([{path : '/'}, {path : '/users'}]);

it is also possible to set an initial route for the router (if omitted, the first route is used):

mockRouter(['/', '/users/:userId'], '/users/4');

or

mockRouter({
  routes : ['/', '/users/:userId'],
  route : '/users/4'
});

the routes can also contain nested routes, just like vue-router:

mockRouter([
  {
    path : '/users',
    children : [
      {
        path : ':userId',
        children : ['edit', 'delete']
      }
    ]
  }
], 'users/4/edit');

The mock router returns a $route and $router object. The two are interlinked - updating the router affects the route object.

results matching ""

    No results matching ""