Module: Turbo::Native::Navigation
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/turbo/native/navigation.rb
Overview
Turbo is built to work with native navigation principles and present those alongside what’s required for the web. When you have Hotwire Native clients running (see the Hotwire Native iOS and Hotwire Native Android projects for details), you can respond to native requests with three dedicated responses: recede
, resume
, refresh
.
Hotwire Native Android and Hotwire Native iOS handle these actions automatically.
Instance Method Summary collapse
-
#hotwire_native_app? ⇒ Boolean
(also: #turbo_native_app?)
Hotwire Native applications are identified by having the string “Hotwire Native” as part of their user agent.
-
#recede_or_redirect_back_or_to(url, **options) ⇒ Object
Same as
recede_or_redirect_to
but redirects to the previous page or provided fallback location if the Turbo Native app is not present. -
#recede_or_redirect_to(url, **options) ⇒ Object
Tell the Turbo Native app to dismiss a modal (if presented) or pop a screen off of the navigation stack.
-
#refresh_or_redirect_back_or_to(url, **options) ⇒ Object
Same as
refresh_or_redirect_to
but redirects to the previous page or provided fallback location if the Turbo Native app is not present. -
#refresh_or_redirect_to(url, **options) ⇒ Object
Tell the Turbo Native app to refresh the current screen, otherwise redirect to the given URL if Turbo Native is not present.
-
#resume_or_redirect_back_or_to(url, **options) ⇒ Object
Same as
resume_or_redirect_to
but redirects to the previous page or provided fallback location if the Turbo Native app is not present. -
#resume_or_redirect_to(url, **options) ⇒ Object
Tell the Turbo Native app to ignore this navigation, otherwise redirect to the given URL if Turbo Native is not present.
Instance Method Details
#hotwire_native_app? ⇒ Boolean Also known as: turbo_native_app?
Hotwire Native applications are identified by having the string “Hotwire Native” as part of their user agent. Legacy Turbo Native applications use the “Turbo Native” string.
15 16 17 |
# File 'app/controllers/turbo/native/navigation.rb', line 15 def hotwire_native_app? request.user_agent.to_s.match?(/(Turbo|Hotwire) Native/) end |
#recede_or_redirect_back_or_to(url, **options) ⇒ Object
Same as recede_or_redirect_to
but redirects to the previous page or provided fallback location if the Turbo Native app is not present.
37 38 39 |
# File 'app/controllers/turbo/native/navigation.rb', line 37 def recede_or_redirect_back_or_to(url, **) turbo_native_action_or_redirect url, :recede, :back, end |
#recede_or_redirect_to(url, **options) ⇒ Object
Tell the Turbo Native app to dismiss a modal (if presented) or pop a screen off of the navigation stack. Otherwise redirect to the given URL if Turbo Native is not present.
22 23 24 |
# File 'app/controllers/turbo/native/navigation.rb', line 22 def recede_or_redirect_to(url, **) turbo_native_action_or_redirect url, :recede, :to, end |
#refresh_or_redirect_back_or_to(url, **options) ⇒ Object
Same as refresh_or_redirect_to
but redirects to the previous page or provided fallback location if the Turbo Native app is not present.
47 48 49 |
# File 'app/controllers/turbo/native/navigation.rb', line 47 def refresh_or_redirect_back_or_to(url, **) turbo_native_action_or_redirect url, :refresh, :back, end |
#refresh_or_redirect_to(url, **options) ⇒ Object
Tell the Turbo Native app to refresh the current screen, otherwise redirect to the given URL if Turbo Native is not present.
32 33 34 |
# File 'app/controllers/turbo/native/navigation.rb', line 32 def refresh_or_redirect_to(url, **) turbo_native_action_or_redirect url, :refresh, :to, end |
#resume_or_redirect_back_or_to(url, **options) ⇒ Object
Same as resume_or_redirect_to
but redirects to the previous page or provided fallback location if the Turbo Native app is not present.
42 43 44 |
# File 'app/controllers/turbo/native/navigation.rb', line 42 def resume_or_redirect_back_or_to(url, **) turbo_native_action_or_redirect url, :resume, :back, end |
#resume_or_redirect_to(url, **options) ⇒ Object
Tell the Turbo Native app to ignore this navigation, otherwise redirect to the given URL if Turbo Native is not present.
27 28 29 |
# File 'app/controllers/turbo/native/navigation.rb', line 27 def resume_or_redirect_to(url, **) turbo_native_action_or_redirect url, :resume, :to, end |