Unexpected token < error in react router component

后端 未结 5 1896
小鲜肉
小鲜肉 2020-11-27 15:17

I\'m trying to write router component for my react app. I\'m create new react class and define some routes in componentDidMount method. This is full method

c         


        
5条回答
  •  无人及你
    2020-11-27 15:24

    If anyone else is having this problem, please check your devtools network tab for server responses. The reason behind the error message is that you are trying to load a javascript/json file and an html file was returned (possibly an error message).

    HTML files start like this normally:

    
    
    ...
    

    The browser sees the first < and gets confused because this is not valid JavaScript so prints out the error message:

    SyntaxError: Unexpected token <
    

    So in the above case, when the OP requested a wrong filename, he got an error page back (in HTML) which lead to that error.

    Hope that helps someone else :)

提交回复
热议问题