我正在尝试添加添加反应路由器-dom,它不允许我。
在这里我得到的错误:
PS D:\spring boot and react training> npm add react-router-dom
npm WARN 保存错误 ENOENT:没有这样的文件或目录,打开'D:\spring boot and react training\package.json'
npm WARN enoent enoent: 没有这样的文件或目录,打开 'D:\spring boot and react training\package.json'
npm WARN mini-create-react-context@0.4.0 需要对等 react@^0.14.0 ||^15.0.0 ||^16.0.0,但未安装任何内容。你必须 自己安装对等依赖项。
npm WARN react-router@5.2.0 需要 react@>=15 的对等体,但没有一个是 安装。您必须自己安装对等依赖项。
npm WARN react-router-dom@5.2.0 需要 react@>=15 的对等体,但没有 已安装。您必须自己安装对等依赖项。
npm 警告 春季启动和反应训练 没有描述
npm 警告 spring 启动和反应训练 无存储库字段。
adding a delete button in react, but it is not working when I click delete this error is shown in chrome console: i can get data from server, not sure why delete does not work.
xhr.js:178 DELETE http://localhost:8080//users/getLoggedInUserName()%20%7B%20%20%20%20let%20user%20=%20sessionStorage.getItem('authenticatedUser');%20%20%20%20if%20(user%20===%20null)%20return%20'';%20%20%20%20return%20user;%20%20%7D/todos/1 500
dispatchXhrRequest @ xhr.js:178
xhrAdapter @ xhr.js:12
dispatchRequest @ dispatchRequest.js:52
Promise.then (async)
request @ Axios.js:61
Axios.<computed> @ Axios.js:76
wrap @ bind.js:9
deleteTodo @ TodoDataService.js:15
deleteTodoClicked @ ListTodoComponent.jsx:60
onClick @ ListTodoComponent.jsx:102
callCallback @ react-dom.development.js:188
invokeGuardedCallbackDev @ react-dom.development.js:237
invokeGuardedCallback @ react-dom.development.js:292
createError.js:16 Uncaught (in promise) Error: Request failed with status code 500
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:61)
here is api:
deleteTodo(name, id){
return Axios.delete(`http://localhost:8080//users/${name}/todos/${id}`)
}
here is my function:
deleteTodoClicked(id){
let username=AuthenticationService.getLoggedInUserName
TodoDataService.deleteTodo(username, id)
.then(
response =>{
this.setState({message : `Delete todos ${id} successful`})
// this.refreshTodos()
}
)
}
on server side console I see this:
2020-05-25 23:28:04.828 WARN 15868 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingPathVariableException: Missing URI template variable 'useranme' for method parameter of type String]
您需要先(手动(安装对等依赖项。
npm install --save-dev <peer-dependency>
然后,npm install --save react-router-dom
解决了问题。为我工作。
npm init
然后npm install react-router-dom
你需要先设置一个包 json,npm init 会自动为你 https://docs.npmjs.com/cli/init
为了通过 npm 安装react-router-dom
,您必须使用install
npm install react-router-dom
使用yarn,您将使用 add 命令
yarn add react-router-dom
似乎你混淆了命令