hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
408 stars 51 forks source link

Ignore query string in path configuration patterns? #248

Closed frederfred closed 1 year ago

frederfred commented 1 year ago

Hi,

I'm wondering if there is a possibility for patterns set in the path configuration config to ignore query strings?

Our use case is that we have one start location for a tab, e.g. /some-path?initial_visit=true, that we then replace with another location for any further visits (just using /some-path). Right now our config looks something like this, which works, but feels a little bit awkward:

{
  …
  "patterns": [
    "^/some-path(\\?start=true)?$"
  ]
  …
}

Maybe adding an option like "ignore_query_string": true in the properties object could be an idea?

Many thanks for providing this framework :)

jayohms commented 1 year ago

Path patterns use normal regular expressions, so we won't be modifying how regex's are evaluated. However, maybe this is helpful? https://github.com/hotwired/turbo-android/pull/178

frederfred commented 1 year ago

Thanks, and sorry for keeping the issue open for long. I forgot about it 🙃

Right now, I'm ignoring any query string in the pattern by doing this:

"patterns": [
  "^/some-path(\\?.*)?$",
],
"properties": {}

I haven't really figured out what "query_string_presentation": "replace" does, but are you saying that this configuration would produce the same result, ignoring any query string in the path?

"patterns": [
  "^/some-path",
],
"properties": {
  "query_string_presentation": "replace"
}
jayohms commented 1 year ago

If you have "query_string_presentation": "replace" configured for your path, it will allow all /some-path* visits (with or without a query string) to act as "replace" visits — meaning that each subsequent /some-path* visit will not push a new destination onto the backstack.

Where we find this helpful at 37signals is when a page contains a content-filter feature, like a drop-down <select> menu. Selecting a new option updates the url with a new query string filter and the current destination is reloaded without adding a new destination onto the backstack.

frederfred commented 1 year ago

Ah, thanks for clarifying that. Then I believe I have to live with "^/some-path(\\?.*)?$" patterns because this used for specifying what fragment I would like to end up on.