module Motion::HTML::UrlHelpers

Defined in:

motion/html/page_helpers/url_helpers.cr

Instance Method Summary

Instance Method Detail

def current_page?(value : String, check_query_params : Bool = false) : Bool #

Tests if the given path matches the current request path.

# Let's say we are visiting https://example.com/shop/products?order=desc&page=1
current_page?("/shop/checkout")
# => false
current_page?("/shop/products")
# => true
current_page?("/shop/products/")
# => true
current_page?("/shop/products?order=desc&page=1")
# => true
current_page?("/shop/products", check_query_params: true)
# => false
current_page?("/shop/products?order=desc&page=1", check_query_params: true)
# => true
current_page?("https://example.com/shop/products")
# => true
current_page?("https://example.io/shop/products")
# => false
current_page?("https://example.com/shop/products", check_query_params: true)
# => false
current_page?("https://example.com/shop/products?order=desc&page=1")
# => true

[View source]
def current_page?(action : Motion::Action.class | Motion::RouteHelper, check_query_params : Bool = false) : Bool #

Tests if the given path matches the current request path.

# Visiting https://example.com/pages/123
current_page?(Pages::Show.with(123))
# => true
current_page?(Posts::Show.with(123))
# => false
# Visiting https://example.com/pages
current_page?(Pages::Index)
# => true
current_page?(Blog::Index)
# => false
# Visiting https://example.com/pages?page=2
current_page?(Pages::Index.with)
# => true
current_page?(Pages::Index.with(page: 2))
# => true
current_page?(Pages::Index.with, check_query_params: true)
# => false
current_page?(Pages::Index.with(page: 2), check_query_params: true)
# => true

[View source]