diff --git a/dist/index.js b/dist/index.js index 966218c4..e7abba74 100644 --- a/dist/index.js +++ b/dist/index.js @@ -262,13 +262,16 @@ var Routes = function () { var wrap = function wrap(method) { return function (route, params, locale, options) { - var _findAndGetUrls = _this4.findAndGetUrls(route, locale, params), + var locale2 = typeof locale === 'string' ? locale : _this4.locale; + var options2 = (typeof locale === 'undefined' ? 'undefined' : (0, _typeof3.default)(locale)) === 'object' ? locale : options; + + var _findAndGetUrls = _this4.findAndGetUrls(route, locale2, params), byName = _findAndGetUrls.byName, _findAndGetUrls$urls = _findAndGetUrls.urls, as = _findAndGetUrls$urls.as, href = _findAndGetUrls$urls.href; - return Router[method](href, as, byName ? options : params); + return Router[method](href, as, byName ? options2 : params); }; }; diff --git a/package.json b/package.json index ff600eb3..449b3655 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,13 @@ "scripts": { "lint": "standard 'src/*' 'test/*'", "build": "del dist/* && babel src -d dist", - "prepublishOnly": "npm run test", + "prepublishOnly": "yarn test", "pretest": "npm run lint && npm run build", - "test": "npm run testOnly", + "test": "yarn testOnly", "testOnly": "jest \\.test.js --coverage", - "testCI": "npm run test && cat coverage/lcov.info | coveralls", - "dev": "concurrently -k 'npm run build -- -w' 'npm run testOnly -- --watch'" + "testCI": "yarn test && cat coverage/lcov.info | coveralls", + "testWatch": "yarn test --watch", + "dev": "concurrently -k 'npm run build -- -w' 'yarn testOnly -- --watch'" }, "standard": { "parser": "babel-eslint" diff --git a/src/index.js b/src/index.js index b0a3a52a..24db7ae6 100644 --- a/src/index.js +++ b/src/index.js @@ -160,8 +160,11 @@ class Routes { getRouter (Router) { const wrap = method => (route, params, locale, options) => { - const {byName, urls: {as, href}} = this.findAndGetUrls(route, locale, params) - return Router[method](href, as, byName ? options : params) + const locale2 = typeof locale === 'string' ? locale : this.locale + const options2 = typeof locale === 'object' ? locale : options + + const {byName, urls: {as, href}} = this.findAndGetUrls(route, locale2, params) + return Router[method](href, as, byName ? options2 : params) } Router.pushRoute = wrap('push') diff --git a/test/index.test.js b/test/index.test.js index 44870afe..ae60b50b 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -192,6 +192,12 @@ describe(`Router ${routerMethods.join(', ')}`, () => { testMethods(['a', {b: 'b'}, 'en', {}], [href, as, {}]) }) + test('with options and without locale', () => { + const {route, testMethods} = setup('a', 'en', '/a/:b') + const {as, href} = route.getUrls({b: 'b'}) + testMethods(['a', {b: 'b'}, { shallow: true }], [href, as, { shallow: true }]) + }) + test('with route not found', () => { setup('a', 'en').testException(['/b', 'en', {}]) })