【发布时间】:2021-11-16 09:26:27
【问题描述】:
pages/index.js 的内容如下:
import { BrowserRouter as Router,History, Switch, Route } from 'react-router-dom';
import TestSocket from '../components/testSocket/TestSocket';
export default function Index(){
return(
<Router>
<Switch>
<Route exact path='/a' component={TestSocket}/>
</Switch>
</Router>
)
}
当我访问页面http://localhost:3000/a时,浏览显示
404 This page could not be found.
这个page 提出了同样的问题,但是,它没有明确说明如何解决这个问题。
您能帮忙详细说明一下解决方案吗?
【问题讨论】:
-
请先阅读
nextjs路由系统。 nextjs.org/docs/routing/introduction -
你的意思是我需要为 /components/testSocket/TestSocket.js 创建一个符号(即 /pages/a.js)目标吗?
-
没错。 Next.js 有一个基于文件系统的路由。