Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ns.router] page.history.replace добавляет url в историю, если она пустая #572

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

## Документация
Expand Down
11 changes: 7 additions & 4 deletions src/ns.page.history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
12 changes: 12 additions & 0 deletions test/spec/ns.page.history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});