Skip to content

Commit deab6d4

Browse files
committed
add test and call onRouteChange every time
1 parent 20c679c commit deab6d4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

router.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ export function Router(props) {
180180
if (prevRoute.current !== path) {
181181
if (wasPush) scrollTo(0, 0);
182182
if (props.onLoadEnd && isLoading.current) props.onLoadEnd(url);
183-
if (props.onRouteChange && !isLoading.current) props.onRouteChange(url);
183+
if (props.onRouteChange) props.onRouteChange(url);
184+
184185
isLoading.current = false;
185186
prevRoute.current = path;
186187
}

test/router.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ describe('Router', () => {
2828
const Profiles = jest.fn(() => html`<h1>Profiles</h1>`);
2929
const Profile = jest.fn(({ params }) => html`<h1>Profile: ${params.id}</h1>`);
3030
const Fallback = jest.fn(() => html`<h1>Fallback</h1>`);
31+
const stack = [];
3132
let loc;
3233
render(
3334
html`
3435
<${LocationProvider}>
35-
<${Router}>
36+
<${Router}
37+
onRouteChange=${url => {
38+
stack.push(url);
39+
}}
40+
>
3641
<${Home} path="/" />
3742
<${Profiles} path="/profiles" />
3843
<${Profile} path="/profiles/:id" />
@@ -111,6 +116,7 @@ describe('Router', () => {
111116
path: '/other',
112117
query: { a: 'b', c: 'd' }
113118
});
119+
expect(stack).toEqual(['/profiles', '/profiles/bob', '/other?a=b&c=d']);
114120
});
115121

116122
it('should wait for asynchronous routes', async () => {

0 commit comments

Comments
 (0)