加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-router – 错误刷新路由器反应路由器

发布时间:2020-12-15 05:07:21 所属栏目:百科 来源:网络整理
导读:当我点击包含url products / new的链接时,我可以访问新的产品页面并且它工作正常,但是如果我刷新页面它会返回Uncaught SyntaxError:Unexpected token. 我该如何解决这个问题? 页面产品新 import React from 'react';class ProductNew extends React.Compon
当我点击包含url products / new的链接时,我可以访问新的产品页面并且它工作正常,但是如果我刷新页面它会返回Uncaught SyntaxError:Unexpected token<. 我该如何解决这个问题? 页面产品新
import React from 'react';

class ProductNew extends React.Component {
  constructor(props) {
    super(props);
  }
  render(){
    return (
      <div>
        <div><h1>ProductNew</h1></div>
      </div>
    );
  }
}

module.exports = ProductNew;

页面产品

import React from 'react';
import { Link }  from 'react-router';

class Products extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div>
        <div><h1>Products</h1></div>
        <Link to="/products/new">new</Link>
      </div>
    );
  }
}

module.exports = Products;

页面应用程序

render((
  <Router history={createBrowserHistory()}>
    <Route path="/" component={Layout}>
       <IndexRoute component={Home} />
       <Route path="/products" component={Products}/>
       <Route path="/products/new" component={ProductNew}/>
    </Route>
  </Router>
),document.getElementById('app'));
我遇到了类似的问题,我的App.js路径是相对的.
因此,当我从主路径加载应用程序页面时,一切运行良好,但当我尝试从您的“/ product / new”链接加载时,我收到了类似您的错误.当我放一条绝对路径时,它工作得很好.

我使用webpack捆绑文件和webpack-dev-server来运行开发环境,当你使用webpack-dev-server热加载器(默认情况下)时没有物理文件,这很容易陷入困境.

编辑:
this guy’s question有2个更新,与你有同样的问题,并有比我给你更好的答案/信息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读