Skip to content

Commit ecfac55

Browse files
rufmanhally9k
authored andcommitted
Add href property to the router state object (#51)
* Add `href` property to the router state object Adding `href` to the router state object gives access to the `$state.href` function in React code. This allows the creation of urls for states, which is critical when a component links to another part of the app and should be crawlable by a crawler. * Update licenser test Include `href` payload key in tests
1 parent 994b8d0 commit ecfac55

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/__tests__/router-listener.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ describe('routerListener', () => {
4444
describe('onStart', () => {
4545
it('must call onStateChangeStart with the transition parameters', () => {
4646
$transitions.onStart.yield($transition$);
47-
expect(ngUiStateChangeActions.onStateChangeStart.calledWith('to', 'toParams', 'from', 'fromParams')).to.equal(true);
47+
expect(ngUiStateChangeActions.onStateChangeStart.calledWith('to', 'toParams', 'from', 'fromParams', 'href')).to.equal(true);
4848
});
4949
});
5050

5151
describe('onError', () => {
5252
it('must call onStateChangeError with the transition parameters and the transition Error', () => {
5353
$transition$.error = sinon.stub().returns('transitionError');
5454
$transitions.onError.yield($transition$);
55-
expect(ngUiStateChangeActions.onStateChangeError.calledWith('to', 'toParams', 'from', 'fromParams', 'transitionError')).to.equal(true);
55+
expect(ngUiStateChangeActions.onStateChangeError.calledWith('to', 'toParams', 'from', 'fromParams', 'href', 'transitionError')).to.equal(true);
5656
});
5757
});
5858

src/router-middleware.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function routerMiddleware($state) {
2828
payload: {
2929
currentState: action.payload.toState,
3030
currentParams: action.payload.toParams,
31+
href: $state.href,
3132
prevState: action.payload.fromState,
3233
prevParams: action.payload.fromParams,
3334
},

0 commit comments

Comments
 (0)