Skip to content

Commit

Permalink
Reset the routing start URL to the current browser URL on reconnected (
Browse files Browse the repository at this point in the history
  • Loading branch information
dicky authored and dicky committed Mar 19, 2021
1 parent 2e30b55 commit ca72240
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 9 additions & 7 deletions DevApp/src/dotnetify/core/dotnetify-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ limitations under the License.
*/
import Path from "../libs/path";
import { createEventEmitter } from "../libs/utils";
import {
IDotnetifyVMRouter,
IDotnetifyVM,
IDotnetifyRouter
} from "../_typings";
import { IDotnetifyVMRouter, IDotnetifyVM, IDotnetifyRouter, IDotnetifyHub } from "../_typings";

export default class DotnetifyRouter implements IDotnetifyRouter {
version = "3.0.0";
Expand All @@ -32,6 +28,7 @@ export default class DotnetifyRouter implements IDotnetifyRouter {

// Internal variable.
_init: boolean = false;
_unsubReconnectedEvent: any;

// URL path that will be parsed when performing routing.
get urlPath(): string {
Expand Down Expand Up @@ -87,8 +84,7 @@ export default class DotnetifyRouter implements IDotnetifyRouter {
// Push state to HTML history.
pushState(iState: any, iTitle: string, iPath: string) {
this.urlPath = "";
if (typeof Path !== "undefined")
Path.history.pushState(iState, iTitle, iPath);
if (typeof Path !== "undefined") Path.history.pushState(iState, iTitle, iPath);
}

// Redirect to the a URL.
Expand All @@ -106,6 +102,12 @@ export default class DotnetifyRouter implements IDotnetifyRouter {
location.replace(iUrl);
}

// Reset the routing start URL to the current browser URL on reconnected.
resetUrlOnReconnected(iHub: IDotnetifyHub) {
if (!this._unsubReconnectedEvent && iHub)
this._unsubReconnectedEvent = iHub.reconnectedEvent?.subscribe(() => (this.urlPath = document.location.pathname));
}

// Called by dotNetify when a view model is ready.
$ready() {
this.$router.initRouting();
Expand Down
3 changes: 3 additions & 0 deletions DevApp/src/dotnetify/core/dotnetify-vm-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export default class DotnetifyVMRouter implements IDotnetifyVMRouter {
this.router = router;
this.debug = vm.$dotnetify.controller.debug;

// Reset the routing start URL to the current browser URL on reconnected (#275).
router.resetUrlOnReconnected(this.vm.$hub);

// Handle 'onRouteEnter' callback being given in the VM options.
if (vm.$options && vm.$options.onRouteEnter) vm["onRouteEnter"] = vm.$options.onRouteEnter;
}
Expand Down

0 comments on commit ca72240

Please sign in to comment.