add 2nd params argument to StackRouter.getActionForPathAndParams (#1623)

* add 2nd params argument to StackRouter.getActionForPathAndParams

It still falls back to parsing the query string if no params argument is provided, but now TabRouter.getActionForPathAndParams which might call StackRouter.getActionForPathAndParams with a 2nd params argument will work correctly. 

In addition, if called directly (as may be the case in apps with custom deep-linking needs [which is my primary case]), it will function correctly without users having to build a query string. 

This also solves the problem that deserialization of query strings is currently implemented without support for cases like nested arrays within the query string.

* Update StackRouter.js
This commit is contained in:
James Gillmore
2017-11-03 12:19:54 -07:00
committed by Vojtech Novak
parent 06cfeb5b2b
commit 7adad618d1

View File

@@ -323,7 +323,10 @@ export default (
};
},
getActionForPathAndParams(pathToResolve: string): ?NavigationStackAction {
getActionForPathAndParams(
pathToResolve: string,
inputParams: ?NavigationParams
): ?NavigationStackAction {
// If the path is empty (null or empty string)
// just return the initial route action
if (!pathToResolve) {
@@ -372,9 +375,9 @@ export default (
// reduce the items of the query string. any query params may
// be overridden by path params
const queryParams = (queryString || '')
.split('&')
.reduce((result: *, item: string) => {
const queryParams =
inputParams ||
(queryString || '').split('&').reduce((result: *, item: string) => {
if (item !== '') {
const nextResult = result || {};
const [key, value] = item.split('=');