3

I'm trying to create routes in my provider but it doesn't work out for nested levels.

Until one level it is working fine.

Find the code snippet below

    render(
  <Provider store={store}>
  <Router history={browserHistory}>
    <Route path="/" component={PageTemplate}>
      <Route path="/login" component={Login}/>
      <Route path="/secure" component={BodyTemplate}>
        <Route path="page1" component={Page1}/>
        <Route path="page2" component={Page2}/>
        <Route path="page3" component={Page3}/>
      </Route>
      <Route path="*" component={InvalidPage}/>
    </Route>
  </Router>
</Provider>, document.getElementById('app'))

If I open the URL localhost:3000/login it is working fine

but if I give the URL localhost:3000/secure/page1 I see the error in the browser console as below

bundle.min.js:1 Uncaught SyntaxError: Unexpected token <

Kindly help me if there is anything wrong in my router configuration.

5
  • Try /page1, /page2, /page3 for the path prop. Commented May 26, 2017 at 11:07
  • I've tried... Its not working.. Even though I Just give the "/" after the first level URL i'm getting the error... eg: "localhost:3000/login" but "localhost:3000/login" works fine Commented May 26, 2017 at 11:08
  • 1
    What does your generated index.html file look like? Specifically, how is the bundle.min.js file being included? Commented May 26, 2017 at 11:12
  • 1
    Got the underlying problem i'm refering as <script src="bundle.min.js"></script> changed to <script src="/bundle.min.js"></script> and its working thanks. Commented May 26, 2017 at 11:18
  • Possible duplicate of Unexpected token < error in react router component Commented May 26, 2017 at 11:18

1 Answer 1

3

Changing the script loading from

<script src="bundle.min.js"></script>

to

<script src="/bundle.min.js"></script>

worked as it is trying to load from ur current url when we go to the second level i.e., localhost:3000/login/bundle.min.js which is wrong changing it to root url made it working localhost:3000/bundle.min.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.