404在尝试重定向到HTML页面时。

huangapple go评论82阅读模式
英文:

404 when trying to redirect to HTML Page

问题

I'm trying to go from a JSX page to an HTML page, but I always get an error when I try to do so. Always a 404 page saying it doesn't exist. It's as if it doesn't exist although I have it clearly in my files and in the same directory.

games.jsx

import React from "react";
import { useEffect, useState } from "react";
import moment from 'moment';
import Link from 'next/link';

export default function Home() {
    const[dataResponse, setdataResponse] = useState([]);
    useEffect(() => {
        async function getPageData() {
            const apiUrlEndpoint = 'http://localhost:3000/api/games';
            const response = await fetch(apiUrlEndpoint);
            const res = await response.json();
            console.log(res.games);
            setdataResponse(res.games);
        }
        getPageData();
    }, []);
    
    return (
        <div className='bg-gray-100 min-h-screen'>
            <a href="newgame.html">Click to Add New Game Product.</a>
            {dataResponse.map((games) => {
                var d = new Date(games.DateWhenAdded);
                var now = moment(d).format('l');
                return (
                    <div key={games.ProductID}>
                        <div>{games.ProductName}</div>
                        <div>
                            <img src={games.ProductImage} width="400" height="400" alt=""/>
                        </div>
                        <div>
                            {games.ProductDescription}
                        </div>
                        <div>
                             Product added on: {now}
                        </div>
                        <div>
                            Product price: ${games.ProductPrice}
                        </div>
                    </div>   
                )
            })}
        </div>
    );
}

And this is the form I'm trying to redirect to. It's called "newgame.html"

<!DOCTYPE html>
<html lang="en">
<head>
<title>
New Game Addition
</title>
</head>
<body>
<form method="post" action="dbcon.php">
    <input type="number" name="ProductID" placeholder="Product ID">
    <input type="text" name="ProductName" placeholder="Name of Product.">
    <input type="text" name="ProductDescription" placeholder="Describe the Product.">
    <input type="file" name="ProductImage" placeholder="Put in Image">
    <input type="date" name="DateWhenAdded" placeholder="01/01/2001">
    <input type="submit" name="submit" value="SUBMIT">
</form>
</body>
</html>

If you can give me any suggestions on what I should try, that would be greatly appreciated. Thank you.

英文:

I'm trying to go from a JSX page to an HTML page, but I always get an error when I try to do so. Always a 404 page saying it doesn't exist. It's as if it doesn't exist although I have it clearly in my files and in the same directory.

games.jsx

import React from &quot;react&quot;;
import { useEffect, useState } from &quot;react&quot;;
import moment from &#39;moment&#39;;
import Link from &#39;next/link&#39;;
export default function Home() {
const[dataResponse, setdataResponse] = useState([]);
useEffect(() =&gt; {
async function getPageData() {
const apiUrlEndpoint = &#39;http://localhost:3000/api/games&#39;;
const response = await fetch(apiUrlEndpoint);
const res = await response.json();
console.log(res.games);
setdataResponse(res.games);
}
getPageData();
}, []);
return (
&lt;div className=&#39;bg-gray-100 min-h-screen&#39;&gt;
&lt;a href=&quot;newgame.html&quot;&gt;Click to Add New Game Product.&lt;/a&gt;
{dataResponse.map((games) =&gt; {
var d = new Date(games.DateWhenAdded);
var now = moment(d).format(&#39;l&#39;);
return (
&lt;div key= {games.ProductID}&gt;
&lt;div&gt;{games.ProductName}&lt;/div&gt;
&lt;div&gt;
&lt;img src={games.ProductImage} width=&quot;400&quot; height=&quot;400&quot; alt=&quot;&quot;/&gt;
&lt;/div&gt;
&lt;div&gt;
{games.ProductDescription}
&lt;/div&gt;
&lt;div&gt;
Product added on: {now}
&lt;/div&gt;
&lt;div&gt;
Product price: ${games.ProductPrice}
&lt;/div&gt;
&lt;/div&gt;   
)
})}
&lt;/div&gt;
);
}

And this is the form I'm trying to redirect to. It's called "newgame.html"

&lt;!DOCTYPE html&gt;
&lt;html lang = &quot;en&quot;&gt;
&lt;head&gt;
&lt;title&gt;
New Game Addition
&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form method=&quot;post&quot; action=&quot;dbcon.php&quot;&gt;
&lt;input type=&quot;number&quot; name=&quot;ProductID&quot; placeholder=&quot;Product ID&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;ProductName&quot; placeholder=&quot;Name of Product.&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;ProductDescription&quot; placeholder=&quot;Describe the Product.&quot;&gt;
&lt;input type=&quot;file&quot; name=&quot;ProductImage&quot; placeholder=&quot;Put in Image&quot;&gt;
&lt;input type=&quot;date&quot; name=&quot;DateWhenAdded&quot; placeholder=&quot;01/01/2001&quot;&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;SUBMIT&quot;&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

If you can give me any suggestions on what I should try, that would be greatly appreciated. Thank you.

答案1

得分: 1

newgame.html文件放入您的public文件夹...

> 这个文件夹还对robots.txtfavicon.ico、Google站点验证和任何其他静态文件(包括.html)非常有用!

并使用以下代码:

&lt;a href=&quot;/newgame.html&quot;&gt;点击以添加新游戏产品。&lt;/a&gt;

请注意URL以/开头。

英文:

Put the newgame.html file into your public folder...

> This folder is also useful for robots.txt, favicon.ico, Google Site Verification, and any other static files (including .html)!

and use the following

&lt;a href=&quot;/newgame.html&quot;&gt;Click to Add New Game Product.&lt;/a&gt;

Note the URL starts with /.

huangapple
  • 本文由 发表于 2023年3月9日 13:27:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75680735.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定