英文:
Next.js not loading file inside
问题
js,我在尝试 Next.js,这是我的目录。
在 counter-state.js 中,我有这段代码:
import {useState} from "react";
function UpdateCounterButton(props){
return <div>
<button onClick={props.updateCount(value=>value+1)}></button>
</div>
}
function CounterRender(props){
return <div>{props.count}</div>
}
export default function CounterState(){
const [counter, setCounter] = useState(0)
return(
<>
<CounterRender count = {counter} />
<UpdateCOunterButton updateCount = {setCounter}/>
</>
)
}
然后我运行
yarn dev
当我访问 localhost:3030 时,
它会打开 Next 的页面
当我访问 localhost:3030/counter/counter-state 时,
它显示 404 错误
请帮忙,我做错了什么!!
英文:
js and i am trying Next.js and this is my directory
and in counter-state.js
I have this code:
import {useState} from "react";
function UpdateCounterButton(props){
return <div>
<button onClick={props.updateCount(value=>value+1)}></button>
</div>
}
function CounterRender(props){
return <div>{props.count}</div>
}
export default function CounterState(){
const [counter, setCounter] = useState(0)
return(
<>
<CounterRender count = {counter} />
<UpdateCOunterButton updateCount = {setCounter}/>
</>
)
}
Then i run
yarn dev
when i go localhost:3030
it opens next's page
and when i go localhost:3030/counter/counter-state
it gives 404 error
any help please what i am doing wrong !!
答案1
得分: 1
在接下来的13步中,为了使此路径正常工作,结构必须如下:在app
文件夹内,添加一个名为counter
的文件夹,在其中再添加一个名为counter-state
的文件夹,然后在这个文件夹中添加一个名为page.js
的文件。
您可以在这里查看更多信息:https://nextjs.org/docs/app/building-your-application/routing
英文:
In Next 13 To be able to make this path work, the structure must be this: Inside app
, a folder counter
, inside this add other folder counter-state
and within this folder add a file named page.js
You can take a look here for more info https://nextjs.org/docs/app/building-your-application/routing
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论