Sha256: af4910462b31a7421e378b77f5c28661d2c564d11bb93138f507e2af3a8ccfd7
Contents?: true
Size: 1.05 KB
Versions: 15
Compression:
Stored size: 1.05 KB
Contents
# backtick_javascript: true class Redirect < Preact::Component EVENT_PUSH_STATE = "pushState" EVENT_REPLACE_STATE = "replaceState" self.context_type = RouterContext if RUBY_ENGINE == 'opal' def initialize(props, context) super(props, context) @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
Version data entries
15 entries across 15 versions & 1 rubygems