node.js - 为什么我的 React.js 应用程序中会出现此错误 'You need to enable javascript'?

标签 node.js reactjs mongodb mern

我在 MERN 堆栈应用程序中收到you need to enable javascript to run this app 错误。除了我为特定路线进行的 api 调用之外,其他一切都工作正常。我使用 axios 包,我在应用程序中进行的所有 API 调用都工作正常,并获取所需的数据并显示在我的浏览器上。问题在于这条特定的路线。同样的路线在 postman 中工作得很好。这是代码:

useEffect(()=>{
const fetchMenu = async () =>{
   try{
         const response = await axiosPrivate.get(`/api/v1/menu`, { withCredentials: true,headers:{authorization: `Bearer ${auth}`}
                });

        console.log(response.data, 'hello menu')
   }catch(err){

   }
}
fetchMenu()
}, [])

如果我通过 postman 调用 API,它可以很好地获取数据。 AxiosPrivate 来自 axios,并且在我使用它的所有地方都运行良好。我真的不知道可能是什么问题。

最佳答案

问题在于我如何调用我的 api。地址应该是 /v1/menu 而不是 /api/v1/menu。这是因为在我的 package.json 文件中已经有这样的代理 "proxy": "http://localhost:5000/api/v1",

关于node.js - 为什么我的 React.js 应用程序中会出现此错误 'You need to enable javascript'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73338937/

相关文章:

javascript - 如果我添加 PropTypes,我需要检查 typeof 吗?

mongodb - 如何使用 ubuntu 中的所有实例完全删除 mongoDB

node.js - Node/ Mongoose : getting to request-context in mongoose middleware

javascript - 如何使用 node.js 创建一个 ActiveXObject?

node.js - 如何在 Windows 10 上修复错误 : spawn UNKNOWN with node. js v7.8.0?

javascript - 在光标处插入 react

javascript - 删除一行 csv 或忽略它

css - React 基本应用程序在本地工作,但在 Azure 中它不加载 .CSS、.Ico、.JSON

python - 将访问 token 存储在用户的集合中更好还是单独存储?

正则表达式 : capturing group?