{"action":"created","issue":{"url":"https://api.github.com/repos/shakacode/react_on_rails/issues/442","repository_url":"https://api.github.com/repos/shakacode/react_on_rails","labels_url":"https://api.github.com/repos/shakacode/react_on_rails/issues/442/labels{/name}","comments_url":"https://api.github.com/repos/shakacode/react_on_rails/issues/442/comments","events_url":"https://api.github.com/repos/shakacode/react_on_rails/issues/442/events","html_url":"https://github.com/shakacode/react_on_rails/issues/442","id":157827326,"number":442,"title":"server render react router Links not changing page","user":{"login":"xiaopow","id":10229915,"avatar_url":"https://avatars.githubusercontent.com/u/10229915?v=3","gravatar_id":"","url":"https://api.github.com/users/xiaopow","html_url":"https://github.com/xiaopow","followers_url":"https://api.github.com/users/xiaopow/followers","following_url":"https://api.github.com/users/xiaopow/following{/other_user}","gists_url":"https://api.github.com/users/xiaopow/gists{/gist_id}","starred_url":"https://api.github.com/users/xiaopow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiaopow/subscriptions","organizations_url":"https://api.github.com/users/xiaopow/orgs","repos_url":"https://api.github.com/users/xiaopow/repos","events_url":"https://api.github.com/users/xiaopow/events{/privacy}","received_events_url":"https://api.github.com/users/xiaopow/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-01T05:38:17Z","updated_at":"2016-10-23T17:21:41Z","closed_at":"2016-06-01T21:12:12Z","body":"Hello, I followed your dummy app to setup client app and server app.\r\n\r\nClient react router app works fine. However for server pre render router app. The Links in the Layout page are not changing the path when clicked. But the server render does work if I manually change the path in the browser. Does anyone might have any idea what might cause this?\r\nThanks.\r\n\r\ngif of issue\r\n![ezgif com-video-to-gif 2](https://cloud.githubusercontent.com/assets/10229915/15699213/f6be3e68-27fd-11e6-8c8c-2c17a0c5546d.gif)\r\n\r\nregistration.jsx\r\n```\r\nimport ReactOnRails from 'react-on-rails';\r\n\r\nimport App from './App';\r\nimport ServerApp from './ServerApp';\r\n\r\nReactOnRails.register({\r\n  App,\r\n  ServerApp\r\n});\r\n```\r\n\r\nServerApp.jsx\r\n```\r\nimport React from 'react';\r\nimport ReactOnRails from 'react-on-rails';\r\nimport { match, RouterContext } from 'react-router';\r\nimport { applyMiddleware, createStore } from 'redux';\r\nimport { Provider } from 'react-redux';\r\nimport thunk from 'redux-thunk';\r\n\r\nimport routes from '../routes/serverAppRoutes';\r\nimport reducer from '../reducers/reducer';\r\n\r\n\r\nexport default (props, railsContext) => {\r\n  let error;\r\n  let redirectLocation;\r\n  let routeProps;\r\n  const { location } = railsContext;\r\n\r\n  const store = createStore(reducer, applyMiddleware(thunk))\r\n\r\n  match({ routes, location }, (_error, _redirectLocation, _routeProps) => {\r\n    error = _error;\r\n    redirectLocation = _redirectLocation;\r\n    routeProps = _routeProps;\r\n  });\r\n  \r\n  if (error || redirectLocation) {\r\n    return { error, redirectLocation };\r\n  }\r\n  \r\n  return (\r\n    <Provider store={store}>\r\n      <RouterContext {...routeProps} />\r\n    </Provider>\r\n  );\r\n};\r\n\r\n// This is how react_on_rails can see the HelloWorldApp in the browser.\r\n```\r\n\r\nserverAppRoutes.js\r\n```\r\nimport React from 'react';\r\nimport { Route, IndexRoute } from 'react-router';\r\n\r\nimport ServerAppRouterLayout from '../components/ServerAppRouterLayout';\r\nimport RouterHomePage from '../components/RouterHomePage';\r\nimport RouterSecondPage from '../components/RouterSecondPage';\r\nimport HelloWorld from '../containers/HelloWorld';\r\n\r\nexport default (\r\n  <Route path=\"server_app\" component={ServerAppRouterLayout}>\r\n    <IndexRoute component={RouterHomePage} />\r\n    <Route path=\"second_page\" component={RouterSecondPage} />\r\n    <Route path=\"hello_world\" component={HelloWorld} />\r\n  </Route>\r\n);\r\n```\r\n\r\nServerAppRouterLayout.jsx\r\n```\r\nimport React from 'react';\r\nimport { Link } from 'react-router';\r\nimport {bindActionCreators} from 'redux'\r\nimport {connect} from 'react-redux';\r\nimport * as actionCreators from '../actions/action_creators';\r\n\r\nconst ServerAppRouterLayout = React.createClass({\r\n  propTypes: {\r\n    children: React.PropTypes.object,\r\n  },\r\n  render: function() {\r\n    return (\r\n      <div className=\"container\">\r\n        <h1>React Router is working!</h1>\r\n        <p>\r\n          Woohoo, we can use <code>react-router</code> here!\r\n        </p>\r\n        <ul>\r\n          <li>\r\n            <Link to=\"/server_app\">\r\n              Router Home Page\r\n            </Link>\r\n          </li>\r\n          <li>\r\n            <Link to=\"/server_app/second_page\">\r\n              Router Second Page\r\n            </Link>\r\n          </li>\r\n          <li>\r\n            <Link to=\"/server_app/hello_world\">\r\n              Hello World\r\n            </Link>\r\n          </li>\r\n        </ul>\r\n        <hr />\r\n        {React.cloneElement(this.props.children,\r\n          {...this.props, key: this.props.location.pathname})}\r\n      </div>\r\n    )\r\n  }\r\n});\r\n\r\nfunction mapStateToProps(state) {\r\n  return {\r\n    store: state\r\n  }\r\n}\r\n\r\nfunction mapDispatchToProps(dispatch) {\r\n  return { actions: bindActionCreators(actionCreators, dispatch) }\r\n}\r\n\r\nexport default connect(\r\n  mapStateToProps,\r\n  mapDispatchToProps\r\n)(ServerAppRouterLayout);\r\n```\r\n\r\nroutes.rb\r\n```\r\nRails.application.routes.draw do\r\n  root 'static_pages#index'\r\n  get 'server_app(/*all)' => 'server_app#index', as: :server_app\r\n\r\n  # get '*path' => 'static_pages#index'\r\nend\r\n```\r\n\r\nserver_app_controller.rb\r\n```\r\nclass ServerAppController < ApplicationController\r\n\r\n  rescue_from ReactOnRails::PrerenderError do |err|\r\n    Rails.logger.error(err.message)\r\n    Rails.logger.error(err.backtrace.join(\"\\n\"))\r\n    redirect_to root_path, flash: { error: \"Error prerendering in react_on_rails. See server logs.\" }\r\n  end\r\n\r\n  def index\r\n    \r\n  end\r\nend\r\n```\r\n\r\nviews/server_app/index.html.erb\r\n```\r\n<h1>Server Rendering</h1>\r\n<%= react_component(\"ServerApp\", props: {}, prerender: true, raise_on_prerender_error: true, trace: true) %>\r\n```\r\n\r\nviews/server_app/second_page.html.erb\r\n```\r\n<%= react_component(\"ServerApp\", props: {}, prerender: true, raise_on_prerender_error: true, trace: true) %>\r\n```\r\n\r\nviews/server_app/hello_world.html.erb\r\n```\r\n<%= react_component(\"ServerApp\", props: {}, prerender: true, raise_on_prerender_error: true, trace: true) %>\r\n```"},"comment":{"url":"https://api.github.com/repos/shakacode/react_on_rails/issues/comments/255601213","html_url":"https://github.com/shakacode/react_on_rails/issues/442#issuecomment-255601213","issue_url":"https://api.github.com/repos/shakacode/react_on_rails/issues/442","id":255601213,"user":{"login":"walidargh","id":16724706,"avatar_url":"https://avatars.githubusercontent.com/u/16724706?v=3","gravatar_id":"","url":"https://api.github.com/users/walidargh","html_url":"https://github.com/walidargh","followers_url":"https://api.github.com/users/walidargh/followers","following_url":"https://api.github.com/users/walidargh/following{/other_user}","gists_url":"https://api.github.com/users/walidargh/gists{/gist_id}","starred_url":"https://api.github.com/users/walidargh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/walidargh/subscriptions","organizations_url":"https://api.github.com/users/walidargh/orgs","repos_url":"https://api.github.com/users/walidargh/repos","events_url":"https://api.github.com/users/walidargh/events{/privacy}","received_events_url":"https://api.github.com/users/walidargh/received_events","type":"User","site_admin":false},"created_at":"2016-10-23T17:21:41Z","updated_at":"2016-10-23T17:21:41Z","body":"I am having a similar issue. Can you share how you fixed your issue?"}}
{"actor":{"display_login":"walidargh"}}