From 3f5ca2177d3a54c9133b5ea6950819ddf3eb1d2d Mon Sep 17 00:00:00 2001 From: Misode Date: Wed, 3 Jun 2020 22:59:37 +0200 Subject: [PATCH] Extract id from pathname correctly --- src/app/app.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/app.ts b/src/app/app.ts index a6a42571..b8cdff28 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -21,8 +21,10 @@ const models: { 'sandbox': new DataModel(SandboxSchema) } +const modelFromPath = (p: string) => p.split('/').filter(e => e.length !== 0).pop() ?? '' + const modelSelector = (document.getElementById('model-selector') as HTMLInputElement) -const defaultModel = location.pathname.replace(/^\//, '') +const defaultModel = modelFromPath(location.pathname) let model = models[defaultModel] const treeViewEl = document.getElementById('tree-view')! @@ -58,8 +60,7 @@ modelSelector.addEventListener('change', evt => { }) window.onpopstate = (evt: PopStateEvent) => { - const newModel = location.pathname.replace(/^\//, '') - updateModel(newModel) + updateModel(modelFromPath(location.pathname)) } const sourceControlsToggle = document.getElementById('source-controls-toggle')!