-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6145 from marmelab/Fix-redirect-to-query-string
Fix useRedirect does not handle query strings
- Loading branch information
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as React from 'react'; | ||
import { useEffect } from 'react'; | ||
import expect from 'expect'; | ||
import { renderWithRedux } from 'ra-test'; | ||
import { createMemoryHistory } from 'history'; | ||
import { Router } from 'react-router-dom'; | ||
|
||
import useRedirect from './useRedirect'; | ||
|
||
const Redirect = ({ redirectTo, basePath = '', id = null, data = null }) => { | ||
const redirect = useRedirect(); | ||
useEffect(() => { | ||
redirect(redirectTo, basePath, id, data); | ||
}, [basePath, data, id, redirect, redirectTo]); | ||
return null; | ||
}; | ||
|
||
describe('useRedirect', () => { | ||
it('should redirect to the path with query string', () => { | ||
const history = createMemoryHistory(); | ||
renderWithRedux( | ||
<Router history={history}> | ||
<Redirect redirectTo="/foo?bar=baz" /> | ||
</Router> | ||
); | ||
expect(history.location).toMatchObject({ | ||
pathname: '/foo', | ||
search: '?bar=baz', | ||
state: { _scrollToTop: true }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters