Skip to content

Commit 3794b25

Browse files
fix(location): do not add hash to URL twice (#847)
* Fix adding the hash to search and path * Add test:watch command to watch output and fix contributing
1 parent acc16d4 commit 3794b25

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

CONTRIBUTING.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Report an Issue
32

43
Help us make UI-Router better! If you think you might have found a bug, or some other weirdness, start by making sure
@@ -17,10 +16,9 @@ is a bug, it's best to talk it out on
1716
[StackOverflow](http://stackoverflow.com/questions/ask?tags=angular2,@uirouter/angular) before reporting it. This
1817
keeps development streamlined, and helps us focus on building great software.
1918

20-
21-
Issues only! |
22-
-------------|
23-
Please keep in mind that the issue tracker is for *issues*. Please do *not* post an issue if you need help or support. Instead, use StackOverflow. |
19+
| Issues only! |
20+
| -------------------------------------------------------------------------------------------------------------------------------------------------- |
21+
| Please keep in mind that the issue tracker is for _issues_. Please do _not_ post an issue if you need help or support. Instead, use StackOverflow. |
2422

2523
# Contribute
2624

@@ -32,13 +30,11 @@ Please keep in mind that the issue tracker is for *issues*. Please do *not* post
3230

3331
**(4)** Finally, commit some code and open a pull request. Code & commits should abide by the following rules:
3432

35-
- *Always* have test coverage for new features (or regression tests for bug fixes), and *never* break existing tests
33+
- _Always_ have test coverage for new features (or regression tests for bug fixes), and _never_ break existing tests
3634
- Commits should represent one logical change each; if a feature goes through multiple iterations, squash your commits down to one
3735
- Make sure to follow the [Angular commit message format](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit-message-format) so your change will appear in the changelog of the next release.
3836
- Changes should always respect the coding style of the project
3937

40-
41-
4238
# Developing
4339

4440
`ui-router-ng2` uses <code>npm</code> and <code>webpack</code>.
@@ -47,8 +43,8 @@ Please keep in mind that the issue tracker is for *issues*. Please do *not* post
4743

4844
The code for `ui-router-ng2` is split into two source repositories:
4945

50-
* [UI-Router Core](https://github.com/ui-router/core) (`@uirouter/core` on npm)
51-
* [UI-Router for Angular 2](https://github.com/ui-router/ng2) (`ui-router-ng2` on npm)
46+
- [UI-Router Core](https://github.com/ui-router/core) (`@uirouter/core` on npm)
47+
- [UI-Router for Angular 2](https://github.com/ui-router/ng2) (`ui-router-ng2` on npm)
5248

5349
Clone both repositories into directories next to each other.
5450

@@ -89,11 +85,10 @@ instead of the prebuilt version specified in `package.json`.
8985

9086
## Develop
9187

92-
* `npm run build`: Perform a full build.
93-
* `npm run watch`: Continuously builds and runs tests when source or tests change.
88+
- `npm run build`: Perform a full build.
89+
- `npm run test:watch`: Continuously builds and runs tests when source or tests change.
9490

9591
If you make changes in `@uirouter/core`, run these scripts before rebuilding or re-testing `@uirouter/angular`:
9692

97-
* `npm run build`: Compiles `@uirouter/core` code
98-
* `npm run watch`: Continuously builds the `@uirouter/core` code when sources change.
99-
93+
- `npm run build`: Compiles `@uirouter/core` code
94+
- `npm run watch`: Continuously builds the `@uirouter/core` code when sources change.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"release": "release --deps @uirouter/core @uirouter/rx",
1111
"check-peer-dependencies": "check-peer-dependencies",
1212
"test": "jest --rootDir test",
13+
"test:watch": "jest --rootDir test --watchAll",
1314
"test:debug": "node --inspect-brk node_modules/.bin/jest --rootDir test --runInBand",
1415
"test:downstream": "test_downstream_projects",
1516
"docs": "generate_docs",

src/location/locationService.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ export class Ng2LocationServices extends BaseLocationServices {
1919

2020
_set(state: any, title: string, url: string, replace: boolean): any {
2121
const { path, search, hash } = parseUrl(url);
22-
const urlPart = search ? path : path + (hash ? '#' + hash : '');
23-
const searchPart = search + (hash ? '#' + hash : '');
22+
23+
const hashWithPrefix = hash ? '#' + hash : '';
24+
let urlPath = path;
25+
let urlParams = search;
26+
27+
if (search) {
28+
urlParams += hashWithPrefix;
29+
} else {
30+
urlPath += hashWithPrefix;
31+
}
2432

2533
if (replace) {
26-
this._locationStrategy.replaceState(state, title, urlPart, searchPart);
34+
this._locationStrategy.replaceState(state, title, urlPath, urlParams);
2735
} else {
28-
this._locationStrategy.pushState(state, title, urlPart, searchPart);
36+
this._locationStrategy.pushState(state, title, urlPath, urlParams);
2937
}
3038
}
3139

test/location/locationService.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ describe('locationService', () => {
4444
expectUrlReadAfterWrite(HashLocationStrategy, '/foo');
4545
});
4646

47+
it('should read/write the url path with single hash', () => {
48+
expectUrlReadAfterWrite(HashLocationStrategy, '/foo#test');
49+
});
50+
4751
it('should read/write query params', () => {
4852
expectUrlReadAfterWrite(HashLocationStrategy, '/foo?query1=value1');
4953
});
@@ -66,6 +70,10 @@ describe('locationService', () => {
6670
expectUrlReadAfterWrite(PathLocationStrategy, '/foo');
6771
});
6872

73+
it('should read/write the url path with single hash', () => {
74+
expectUrlReadAfterWrite(PathLocationStrategy, '/foo#test');
75+
});
76+
6977
it('should read/write query params', () => {
7078
expectUrlReadAfterWrite(PathLocationStrategy, '/foo?query1=value1');
7179
});

0 commit comments

Comments
 (0)