This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Need instructions on how to make things work with prererendering #6
Comments
To use the router with prerendering, you have to use memory history while prerendering. To do this you will have to pass your path up from the rails controller, and then redefined the history memory to use the correct history. For example: module Components
class Router < React::Router
param :url_path
def history
if React::IsomorphicHelpers.on_opal_client?
browser_history
else
path = params.url_path
`ReactRouter.createMemoryHistory(#{path});`
end
end
end
end This would be awesome to just add this in to the reactrb-router code, but here we are dependent on the url param being passed down from the Rails controller. |
So to clarify the above... you would also have to pass the current_path from the controller/layout through your components to the router. i.e. I believe we can fully automate this approx like this: ... in React::Router class ...
include IsomorphicHelpers
class << self
attr_reader :path
end
before_first_mount do |context|
# capture the path from the controller if we are on the server
@path = context.controller.request['path'] if on_opal_server?
end
...
# later in browser_history definition:
def browser_history
if Router.on_opal_server?
path = Router.path.gsub... blah blah (strip it down to whatever part of the path the history deals with
`ReactRouter.createMemoryHistory(#{path})`
else
... do the normal stuff
end
end
# repeat for the other predefined history methods... |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
@adamcreekroad can you help with this... how do you do it at catprint / change requests app
The text was updated successfully, but these errors were encountered: