diff --git a/README.md b/README.md index 7268cf0c..581edb85 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -[![Build Status](https://travis-ci.org/yandex-ui/noscript.png?branch=master)](https://travis-ci.org/yandex-ui/noscript) -[![NPM version](https://badge.fury.io/js/noscript.png)](http://badge.fury.io/js/noscript) -[![Dependency Status](https://david-dm.org/yandex-ui/noscript.png)](https://david-dm.org/yandex-ui/noscript) +[![Build Status](https://travis-ci.org/yandex-ui/noscript.svg?branch=master)](https://travis-ci.org/yandex-ui/noscript) +[![NPM version](https://badge.fury.io/js/noscript.svg)](http://badge.fury.io/js/noscript) +[![Dependency Status](https://david-dm.org/yandex-ui/noscript.svg)](https://david-dm.org/yandex-ui/noscript) # noscript - JS MVC framework ## Документация diff --git a/src/ns.page.history.js b/src/ns.page.history.js index e8b37f7e..7b43ac7c 100644 --- a/src/ns.page.history.js +++ b/src/ns.page.history.js @@ -54,10 +54,13 @@ ns.page.history.replace = function(url) { var nsHistory = ns.page.history; - // remove prev - nsHistory._history.pop(); - // insert new - nsHistory._history.push(url); + if (nsHistory._current) { + // remove prev + nsHistory._history.pop(); + // insert new + nsHistory._history.push(url); + } + // save current nsHistory._current = url; }; diff --git a/test/spec/ns.page.history.js b/test/spec/ns.page.history.js index 4055aa6c..b4816c4d 100644 --- a/test/spec/ns.page.history.js +++ b/test/spec/ns.page.history.js @@ -25,4 +25,16 @@ describe('ns.page.history', function() { }); + describe('.replace', function() { + it('не должен записать историю при первом переходе', function() { + ns.page.history.replace('/app'); + expect(ns.page.history.getPrevious()).to.be.equal(undefined); + }); + + it('должен переписать историю', function() { + ns.page.history.push('/app1'); + ns.page.history.replace('/app2'); + expect(ns.page.history.getPrevious()).to.be.equal('/app2'); + }); + }); });