React-router: if I go to nested route directly, error ReactJS

Created on 27 May 2016  ·  5Comments  ·  Source: ReactTraining/react-router

Hej,

I can go to a nested route by starting from the entry point e.g. localhost/, step by step to http://localhost:8080/huge-apps/course/0/assignments, but if I copy this link and paste to browser, it will give me error.

app.js:1 Uncaught SyntaxError: Unexpected token < the page is not render at all, with this info it is really hard to tell where goes wrong.

I was wondering if it is caused by webpack configuration, as before I had the problem with require.ensure([], (**require**) 0 => {}) as the second require in parameter caused problems.

Any idea?

Most helpful comment

since this page comes up near the top of searches for “react router redux Uncaught SyntaxError: Unexpected token <”, I'll add my 2 cents. Like @rizkiandrianto, my problem was in the script tag. The tutorial I was following used src='./bundle.js' which was fine until new routes were introduced. Dropping the . and going with src='/bundle.js' was the solution.

All 5 comments

You probably need to configure your server appropriately. See the guides.

Hej, can you please be more specify, like which guides? I use Express server, do you mean the server route, or webpack configuration? I do not use the webpack-dev-server. I notice some client side JS error can cause Unexpected token < happened, but there is no more details to trace the cause.

I looked the log, it looks like nested route was added in the front of the webpack servinig path: GET /23423423/assets/app.js 304 3.144 ms - - while I put in localhost:3000/23423423/fdghf, i.e. 23423423 shall be cleared as well.

Any idea?

ok, never mind, it was the . in the index.html page where it fetches the entry point causing the problem.

Hey @Kenzku what did you mean with ok, never mind, it was the . in the index.html page where it fetches the entry point causing the problem. ?
How did you get it works?

Edited:
I figured it out by placing / before calling my bundle.js

since this page comes up near the top of searches for “react router redux Uncaught SyntaxError: Unexpected token <”, I'll add my 2 cents. Like @rizkiandrianto, my problem was in the script tag. The tutorial I was following used src='./bundle.js' which was fine until new routes were introduced. Dropping the . and going with src='/bundle.js' was the solution.

Hej @rizkiandrianto yes, in the entry html or js, whatever you use as an entry point to load the rest of the files. like what @shoesandsocks said. Sorry, I have been hibernating for 2 years in bed.

Was this page helpful?
0 / 5 - 0 ratings