如何在下一阶段采取动态路线 J. 14 采用打字方式? 进口{使用舱面},取自未出现的“next/router”错误。
// editTask/[editTask]/page.tsx
"use client";
import { useEffect, useState } from "react";
import axios from "axios";
进口{使用舱面},“next/router”;
const EditTask: React.FC = () => {
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
const [completed, setCompleted] = useState(false);
const router = useRouter();
const { id } = router.query;
useEffect(() => {
const fetchTask = async () => {
try {
const res = await axios.get(`http://localhost:5555/tasks/${id}`);
const task = res.data;
setTitle(task.title);
setDescription(task.description);
setCompleted(task.completed);
} catch (err) {
console.error(err);
}
};
if (id) {
fetchTask();
}
}, [id]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
const updatedTask = {
title,
description,
completed,
};
try {
await axios.put(`http://localhost:5555/tasks/${id}`, updatedTask);
router.push("/");
} catch (err) {
console.error(err);
}
};
if (!id) return null;
这里的错误
进口{使用舱面},“next/router”;
const router = useRouter();
如何加以确定?