Skip to content
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

Path Parameters #1048

Open
ddouglas opened this issue Mar 5, 2025 · 1 comment
Open

Path Parameters #1048

ddouglas opened this issue Mar 5, 2025 · 1 comment

Comments

@ddouglas
Copy link

ddouglas commented Mar 5, 2025

I'm probably going to be using Go-App in an unorthodox way by not encouraging my audience to install the PWA and instead just running it directly in the browser. That aside, I'd like to be able to use the url to persist state between pages allowing my users to link directly to specific pages. I'd love it if it was with path parameters, but I'm okay with just query parameters, but I can't figure out how to extract even the current url in the component. Do I need to call JS to get the current url? I've seen it mentioned a couple of times in other issues that some have implemented their own router sortof that allows for parameters in the path. I'd love it if somebody can share their implementations, even if they're dumped down ones.

@oderwat
Copy link
Contributor

oderwat commented Mar 5, 2025

We use JS to get and set the hash of the URL instead of changing the URL itself.

But for returning users we actually prefer using session data. You do not need to have them install the PWA for any of its functionality. It does not make a lot of difference. The main difference in my eyes is the screen real-estate and them having a nice "button" for the app.

package jgasm

import "github.com/maxence-charriere/go-app/v10/pkg/app"

func GetHash() string {
	loc := app.Window().Get("location")
	hash := loc.Get("hash").String()
	if len(hash) < 2 {
		return ""
	}
	return hash[1:]
}

func SetHash(hash string) {
	loc := app.Window().Get("location")
	doc := app.Window().Get("document")
	hist := app.Window().Get("history")
	if hist.Truthy() {
		if hash != "" {
			hash = "#" + hash
		}
		hist.Call("pushState", "", doc.Get("title"),
			loc.Get("pathname").String()+loc.Get("search").String()+hash)
	} else {
		loc.Set("hash", hash)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants