1

I am having a problem with browserHistory in react-router 2.0.0-rc. I am trying to get an edit page to work by using a react-router param for the username, followed by a nested static route called 'edit'. When I use react-router links, the page loads as expected, but after entering the url manually or refreshing, the page shows up blank with a bundle error Uncaught SyntaxError: Unexpected token <.

All of my other routes work fine. Unfortunately all of the docs seem to use static followed by dynamic route params and not the other way around.

Here are my routes:

<Route path="/" component={App} onEnter={currentUserCheck}>
    <IndexRoute component={HomePage} />
    <Route path="/signup" component={SignupForm} />
    <Route path="/login" component={LoginForm} />
    <Route path="/chart" component={PollResult} />
    <Route path="/:username/edit" component={EditProfile}/>
    <Route path="/:username" component={ProfilePage}/>
    <Route path="*" component={NoMatch}/>
</Route>
GSerg
  • 76,472
  • 17
  • 159
  • 346
Chris Dziewa
  • 190
  • 10
  • Are other routes working when you refresh or access them directly? I think you need to create a server route that serves your react app and knows to handle any url, not just the root url. Maybe check this answer and see if it is what you need: http://stackoverflow.com/questions/16579404/url-rewriting-with-expressjs. Additionally, you need to make sure that you use babel on the "server side" also, because that error sounds like JSX is not recognized on the server – Alex Moldovan Feb 23 '16 at 19:11
  • All my other routes work fine. I have a catch all route on my express server that redirects to my index page where my bundle is served. I'm towards the end of my project. This is the first problem I've had like this. – Chris Dziewa Feb 23 '16 at 19:22
  • Thanks for your help. I was able to figure it out. – Chris Dziewa Feb 23 '16 at 20:30
  • Please [do not use "solved"](http://meta.stackoverflow.com/q/311829/11683) in the question title or body. – GSerg Feb 23 '16 at 20:39
  • Alright, I was just trying to let people know they could skip over it. It won't let me mark the answer correct for 2 days and the only other option was to delete it. – Chris Dziewa Feb 23 '16 at 20:45

1 Answers1

9

I figured it out. I needed to put a / before my bundle and css files in my index.html. With my other routes I was fine since they were top level routes, but once I moved down into nested routes, I lost reference to the static assets.

Chris Dziewa
  • 190
  • 10