Browserhistory (react-router) with firebase

716 views
Skip to first unread message

Emmanuel Henri

unread,
Apr 1, 2016, 11:03:37 AM4/1/16
to Firebase Google Group
Is it possible with FIREBASE to do browserhistory for react-router.

See react-router browserhistory docs if you need more details: https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#browserhistory

Usually we implement this at the server (expressJS) level and was wondering if there are any ways we can do this on firebase. 

Jacob Wenger

unread,
Apr 1, 2016, 12:55:35 PM4/1/16
to fireba...@googlegroups.com
Hey Emmanuel,

What are you trying to accomplish? Are you trying to sync what page people are on by storing their current page in Firebase? Or are you trying to do something else?

In general, creating a custom history in ReactRouter using Firebase is not going to work. You can probably store a user's current route in a /users/$uid/currentRoute node and have other client's listen for change to that node and then use browserHistory.push('/some/path/from/firebase') to navigate everyone to the same page.

Your original post is a bit of an XY problem. It would be better to ask about what you are actually trying to accomplish.

Cheers,
Jacob

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/6c8a1144-bd8d-4056-b5ee-021d0aff32f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jacob Wenger

unread,
Apr 1, 2016, 1:03:38 PM4/1/16
to Jacob Wenger, fireba...@googlegroups.com
Ahh okay so one of my teammates told me you are probably asking how to get ReactRouter working with Firebase Hosting. To do that, you just need to add a "rewrites" rule to your firebase.json which maps all routes to /index.html:

{
  "firebase": "<YOUR-FIREBASE-APP>",
  "public": "<YOUR-PUBLIC-DIRECTORY>",
  "ignore": [
    "firebase.json",
    "**/.*",
    "**/node_modules/**"
  ],
  "rewrites": [
    {
      "source": "**",
      "destination": "/index.html"
    }
  ]
}

Cheers,
Jacob

Nick Bae

unread,
Apr 8, 2016, 10:41:35 AM4/8/16
to Firebase Google Group, ja...@firebase.com
I was up for DAYS looking for something like this on the web!!! Thanks Emmanuel for posting this question, and the Firebase team for the prompt response. This kind of stuff really helps new developers such as myself :)

jasan singh

unread,
May 31, 2016, 10:05:13 PM5/31/16
to Firebase Google Group, ja...@firebase.com
Nick, where you able to use browserHistory+ react-router with firebase using the above snippet? 
Reply all
Reply to author
Forward
0 new messages