-
-
Notifications
You must be signed in to change notification settings - Fork 241
fix(router): query params not being saved #2062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NathanWalker
merged 13 commits into
NativeScript:master
from
edusperoni:location-strategy
Jun 5, 2020
+80
−16
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ecfc789
fix(router): query params not being saved
edusperoni c962f01
test pages
edusperoni 02f543a
chore: update router tests
edusperoni faf5e9e
chore: update typings
edusperoni 32ce30a
chore: add query params back test
edusperoni 47d61cc
add params to primary outlet and always make copy
edusperoni 0bc1bda
chore: thorough test case
edusperoni a7de68f
chore: fix lint
edusperoni fd239cf
Merge branch 'master' into location-strategy
lini ff9fb1f
update typedoc version
lini 21cd7f2
Merge branch 'master' into location-strategy
NathanWalker 14f6874
Merge branch 'master' into location-strategy
NathanWalker 76e8e59
Merge branch 'master' into location-strategy
NathanWalker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { LocationStrategy } from "@angular/common"; | ||
import { DefaultUrlSerializer, UrlSegmentGroup, UrlTree, ActivatedRouteSnapshot } from "@angular/router"; | ||
import { DefaultUrlSerializer, UrlSegmentGroup, UrlTree, ActivatedRouteSnapshot, Params } from "@angular/router"; | ||
import { routerLog, routerError, isLogEnabled } from "../trace"; | ||
import { NavigationTransition, Frame } from "@nativescript/core/ui/frame"; | ||
import { isPresent } from "../lang-facade"; | ||
|
@@ -85,6 +85,7 @@ const defaultNavOptions: NavigationOptions = { | |
}; | ||
|
||
export interface LocationState { | ||
queryParams: Params; | ||
segmentGroup: UrlSegmentGroup; | ||
isRootSegmentGroup: boolean; | ||
isPageNavigation: boolean; | ||
|
@@ -131,6 +132,7 @@ export class NSLocationStrategy extends LocationStrategy { | |
} | ||
|
||
const urlSerializer = new DefaultUrlSerializer(); | ||
tree.queryParams = state.queryParams; | ||
const url = urlSerializer.serialize(tree); | ||
if (isLogEnabled()) { | ||
routerLog("NSLocationStrategy.path(): " + url); | ||
|
@@ -165,10 +167,11 @@ export class NSLocationStrategy extends LocationStrategy { | |
const outletKey = this.getOutletKey(this.getSegmentGroupFullPath(segmentGroup), "primary"); | ||
const outlet = this.findOutlet(outletKey); | ||
|
||
if (outlet && this.updateStates(outlet, segmentGroup)) { | ||
if (outlet && this.updateStates(outlet, segmentGroup, this.currentUrlTree.queryParams)) { | ||
this.currentOutlet = outlet; // If states updated | ||
} else if (!outlet) { | ||
const rootOutlet = this.createOutlet("primary", null, segmentGroup, null); | ||
// tslint:disable-next-line:max-line-length | ||
const rootOutlet = this.createOutlet("primary", null, segmentGroup, null, null, this.currentUrlTree.queryParams); | ||
this.currentOutlet = rootOutlet; | ||
} | ||
|
||
|
@@ -197,15 +200,15 @@ export class NSLocationStrategy extends LocationStrategy { | |
const containsLastState = outlet && outlet.containsTopState(currentSegmentGroup.toString()); | ||
if (!outlet) { | ||
// tslint:disable-next-line:max-line-length | ||
outlet = this.createOutlet(outletKey, outletPath, currentSegmentGroup, parentOutlet, this._modalNavigationDepth); | ||
outlet = this.createOutlet(outletKey, outletPath, currentSegmentGroup, parentOutlet, this._modalNavigationDepth, this.currentUrlTree.queryParams); | ||
this.currentOutlet = outlet; | ||
} else if (this._modalNavigationDepth > 0 && outlet.showingModal && !containsLastState) { | ||
// Navigation inside modal view. | ||
this.upsertModalOutlet(outlet, currentSegmentGroup); | ||
this.upsertModalOutlet(outlet, currentSegmentGroup, this.currentUrlTree.queryParams); | ||
} else { | ||
outlet.parent = parentOutlet; | ||
|
||
if (this.updateStates(outlet, currentSegmentGroup)) { | ||
if (this.updateStates(outlet, currentSegmentGroup, this.currentUrlTree.queryParams)) { | ||
this.currentOutlet = outlet; // If states updated | ||
} | ||
} | ||
|
@@ -604,15 +607,16 @@ export class NSLocationStrategy extends LocationStrategy { | |
return outlet; | ||
} | ||
|
||
private updateStates(outlet: Outlet, currentSegmentGroup: UrlSegmentGroup): boolean { | ||
private updateStates(outlet: Outlet, currentSegmentGroup: UrlSegmentGroup, queryParams: Params): boolean { | ||
const isNewPage = outlet.states.length === 0; | ||
const lastState = outlet.states[outlet.states.length - 1]; | ||
const equalStateUrls = outlet.containsTopState(currentSegmentGroup.toString()); | ||
|
||
const locationState: LocationState = { | ||
segmentGroup: currentSegmentGroup, | ||
isRootSegmentGroup: false, | ||
isPageNavigation: isNewPage | ||
isPageNavigation: isNewPage, | ||
queryParams: {...queryParams} | ||
}; | ||
|
||
if (!lastState || !equalStateUrls) { | ||
|
@@ -645,14 +649,15 @@ export class NSLocationStrategy extends LocationStrategy { | |
} | ||
|
||
// tslint:disable-next-line:max-line-length | ||
private createOutlet(outletKey: string, path: string, segmentGroup: any, parent: Outlet, modalNavigation?: number): Outlet { | ||
private createOutlet(outletKey: string, path: string, segmentGroup: any, parent: Outlet, modalNavigation?: number, queryParams: Params = {}): Outlet { | ||
const pathByOutlets = this.getPathByOutlets(segmentGroup); | ||
const newOutlet = new Outlet(outletKey, path, pathByOutlets, modalNavigation); | ||
|
||
const locationState: LocationState = { | ||
segmentGroup: segmentGroup, | ||
isRootSegmentGroup: false, | ||
isPageNavigation: true // It is a new OutletNode. | ||
isPageNavigation: true, // It is a new OutletNode. | ||
queryParams: {...queryParams} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here:
|
||
}; | ||
|
||
newOutlet.states = [locationState]; | ||
|
@@ -719,7 +724,7 @@ export class NSLocationStrategy extends LocationStrategy { | |
} | ||
} | ||
|
||
private upsertModalOutlet(parentOutlet: Outlet, segmentedGroup: UrlSegmentGroup) { | ||
private upsertModalOutlet(parentOutlet: Outlet, segmentedGroup: UrlSegmentGroup, queryParams: Params) { | ||
let currentModalOutlet = this.findOutletByModal(this._modalNavigationDepth); | ||
|
||
// We want to treat every p-r-o as a standalone Outlet. | ||
|
@@ -734,9 +739,9 @@ export class NSLocationStrategy extends LocationStrategy { | |
const outletPath = parentOutlet.peekState().segmentGroup.toString(); | ||
const outletKey = this.getOutletKey(outletPath, outletName); | ||
// tslint:disable-next-line:max-line-length | ||
currentModalOutlet = this.createOutlet(outletKey, outletPath, segmentedGroup, parentOutlet, this._modalNavigationDepth); | ||
currentModalOutlet = this.createOutlet(outletKey, outletPath, segmentedGroup, parentOutlet, this._modalNavigationDepth, queryParams); | ||
this.currentOutlet = currentModalOutlet; | ||
} else if (this.updateStates(currentModalOutlet, segmentedGroup)) { | ||
} else if (this.updateStates(currentModalOutlet, segmentedGroup, queryParams)) { | ||
this.currentOutlet = currentModalOutlet; // If states updated | ||
} | ||
} | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be best to use some protection here in case queryParams comes in null or undefined?