javascript - 如何建立直接链接,从而重置 React-router-dom 中的整个路径
问题描述
我有这种情况,我发现的Router
副作用是,例如,当我在某些地方并localhost:3000/tododetails/some_id
单击例如链接:我怎样才能编辑它以正常工作?试图在里面创建一个绝对路径,像这样:,但结果比以前更糟。Notes Form
localhost:3000/notesform
localhost:3000/tododetails/notesform
Link
localhost:3000/notesform
localhost:3000/tododetails/localhost:3000/notesform
我的路由器:
<BrowserRouter>
<ul>
<li><Link to="todolist">Todo List</Link></li>
<li><Link to="todoform">Todo Form</Link></li>
<li><Link to="noteslist">Notes List</Link></li>
<li><Link to="notesform">Notes Form</Link></li>
</ul>
<Route exact path="/todolist" component={TodoList} />
<Route exact path="/todoform" component={TodoForm} />
<Route exact path="/todoform/:id" component={TodoForm} />
<Route exact path="/tododetails/:id" component={TodoDetails} />
<Route exact path="/noteslist" component={NotesList} />
<Route exact path="/notesform" component={NotesForm} />
<Route exact path="/notesform/:id" component={NotesForm} />
<Route exact path="/notesdetails/:id" component={NotesDetails} />
</BrowserRouter>
解决方案
您必须以 a 开头的链接值/
如下:
<li><Link to="/todolist">Todo List</Link></li>
<li><Link to="/todoform">Todo Form</Link></li>
<li><Link to="/noteslist">Notes List</Link></li>
<li><Link to="/notesform">Notes Form</Link></li>
否则,它被认为是一个相对链接。
推荐阅读
- java - 为 HBox 设置背景图像 - JavaFX
- hex - STM32反编译器
- c# - 如何在 C# EF 核心 web api 中将列表转换为 Json
- python - python递归追加到列表
- c# - BindingSource.EndEdit() 与 TableAdapterManager.UpdateAll()
- c - 为什么我无法释放内存?无效的 free() / delete / delete[] / realloc()
- testing - 如何pytest从数据库读取的函数?
- angular - 使用 Observable 获取数据时,需要使用detector.detectChanges Angular v6+
- r - 竞争风险/生存分析 R
- .net - 在 .net 3.1 凭据错误中调用 Powershell 核心中的 Restart-Computer 但在 Powershell 中工作