Sha256: 8b7d28f1b855f0ada6d9cf2a4b6b6befa011601a94e05a73ad6e41d7bd9f5ee1
Contents?: true
Size: 1.01 KB
Versions: 9
Compression:
Stored size: 1.01 KB
Contents
class Redirect < Preact::Component EVENT_PUSH_STATE = "pushState" EVENT_REPLACE_STATE = "replaceState" def initialize(props, context) super(props, context) if RUBY_ENGINE == 'opal' @history = if `typeof window !== "undefined"` `window.history` else `{ length: 1, state: null, scrollRestoration: "auto", pushState: function(e,t,n){}, replaceState: function(e,t,n){} }` end @base = '' end end def navigate if RUBY_ENGINE == 'opal' to = props[:to] || props[:href] m = props[:replace] ? EVENT_REPLACE_STATE : EVENT_PUSH_STATE `#@history[m](null, "", to[0] === "~" ? to.slice(1) : #@base + to)` context[:router][:callback].call if context[:router].key?(:callback) end end render do if RUBY_ENGINE == 'opal' @base = context[:router][:base] if context[:router].key?(:base) navigate end nil end end Redirect.context_type = RouterContext
Version data entries
9 entries across 9 versions & 1 rubygems