账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react 路由 webpack调试正常,打包后路由不起作用
    • 2018-06-26 00:00
    • 10
    28
    0

    在webpack的服务器8080端口开发调试好好的,本地80端口只能打开主页,其他路径都是报错的
    [an error occurred while processing this directive] The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again. [an error occurred while processing this directive]
    这是页面报错信息
    下面是控制台报错信息
    Error in event handler for (unknown): TypeError: Cannot read property 'textContent' of null
    at displayError (chrome-extension://chklaanhfefbnpoihckbnefhakgolnmc/content.js:4:99)
    at chrome-extension://chklaanhfefbnpoihckbnefhakgolnmc/content.js:282:4

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 我予春风 普通会员 1楼

      在React中,使用Webpack调试和打包路由时,如果路由不起作用,可能是由于以下原因:

      1. 在Webpack配置中没有正确配置路由。在webpack.config.js文件中,需要设置history属性来启用路由。例如:

      javascript module.exports = { //... history: { mode: 'history', }, };

      1. 配置了history.push()方法,但没有正确地访问页面。在History.js文件中,需要配置push()方法来正确地访问页面。例如:

      ```javascript import { History } from 'react-router-dom';

      export default new History(); ```

      1. 使用了React Router的某个插件或API,但没有正确地配置它。例如,如果你使用了react-router-domLink组件,但没有配置to属性,那么即使你的路由看起来是正确的,路由也可能不起作用。例如:

      ```javascript import Link from 'react-router-dom';

      const MyLink = Link( '/my-page', { to: '/my-page', }, ); ```

      如果你怀疑是上述原因中的某个问题,可以尝试以下步骤来调试和解决:

      • 检查Webpack配置,确保正确的路由设置。
      • 检查路由在实际页面中的表现,确保它们按预期工作。
      • 检查React Router的插件和API,确保它们按预期工作。
      • 如果上述方法都无法解决问题,可以考虑将你的React应用部署到服务器上,然后使用浏览器的开发者工具来调试和测试你的路由。
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部