Adding history support

Arriving on a new map now changes the URL.
All URLs starting with _ are automatically redirected to index.html by the web server
This commit is contained in:
David Négrier 2020-05-12 00:07:50 +02:00
parent 9417e4a4d2
commit daa559738b
4 changed files with 40 additions and 0 deletions

View file

@ -151,6 +151,15 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat
context.strokeStyle = '#ffffff';
context.stroke();
this.circleTexture.refresh();
// Let's alter browser history
let url = new URL(this.MapUrlFile);
let path = '/_/'+url.host+url.pathname;
if (url.hash) {
// FIXME: entry should be dictated by a property passed to init()
path += '#'+url.hash;
}
window.history.pushState({}, null, path);
}
private getExitSceneUrl(layer: ITiledMapLayer): string|undefined {