Next.js Discord

Discord Forum

Issue linking to local file BEGINNER

Answered
bobonlan posted this in #help-forum
Open in Discord
I have a react component with the linkTo prop set up, but when I try hitting the button I get a 404. I'm 99.999% certain my path is correct, but I know I could easily be wrong.

Here is my code:
//@refresh reset
import { useState } from "react";
function Header({ title }) {
return (
<h1
style={{
backgroundColor: "aqua",
textAlign: "center",
}}
>
{title ? title : "bobonlan.com"}
</h1>
);
}

function BasicButton({ title, linkTo }) {
return (
<a href={linkTo}>
<button
style={{
width: "100px",
height: "30px",
borderRadius: "15px",
fontFamily: "Arial",
fontSize: "15px",
letterSpacing: "0.5px",
fontWeight: "bold",
textDecoration: "none solid rgb(68, 68, 68)",
fontStyle: "italic",
fontVariant: "normal",
textTransform: "uppercase",
color: "fuchsia",
cursor: "pointer",
}}
>
{title}
</button>
</a>
);
}

export default function HomePage() {
return (
<div>
<Header title="bobonlan.com" />
<BasicButton title="twitch.tv" linkTo="https://twitch.tv/bobonlan" />
<BasicButton title="twitter" linkTo="https://twitter.com/bobonlan" />
<BasicButton
title="what the"
linkTo="./../Real Web Page Shit/Minesweeper/Menu Screen/indexone.html"
/>
</div>
);
}
Answered by fuma
Don't do that, your page must be javascript/typescript
For a normal HTML file, put it in /public and serve it as static assets
View full answer

37 Replies

The buttons linking to actual websites work, just the one linking to a local file gives a 404
You aren't supposed to use .html and whitespace in a url, what is that file actually?
If it's not under /public folder, you can't access it
i thought it had to be /pages
For a page, you don't need to add .html at the end of url
and for the spaces do %20?
I have an index.js inside a folder called pages, and the folder Real Web Page Shit in the path from earlier is also inside the folder called pages
I don't know what you are referring, are you using Pages Router (/pages dir)?
And you have a page in /pages/Real Web Page Shit/index.js?
I followed along with the Learn Next.js tutorial and when it got to the make your own app thing I started doing custom stuff to make a website type thing. I don't know what a Router is so I assume not, my stuff is just loading in localhost 3000. One moment and I can send a screencap with my folder paths
ignore testes
Don't do that, your page must be javascript/typescript
For a normal HTML file, put it in /public and serve it as static assets
Answer
is html not in part js? i thought the three (css being the 3rd) all seamlessly worked together
HTML is replaced by jsx/tsx, so that you can use React.js
do i need /public to be inside of /pages or does it need to be somewhere else?
no, root directory of your project
@fuma no, root directory of your project
outermost shell right
However, for normal pages, use javascript/typescript instead
So I can still have it run the HTML page but going forward I should make things in js/ts, or am I gonna have to rebuild everything into a single js file
rebuild your pages in Javascript/Typescript, with React.js
rip
good practice i suppose
When I rebuild them in JS/TS, do I still need to put the file itself in /public or will it be fine in a folder inside of /public
of course no, all the pages are located under /pages
You should read the tutorial and documentation
I have one last question before I do that
The first step of it is to do npx create-react-app, do I need to be in a folder called /public when i open the terminal
like it would mess stuff up if i was in my existing index.js and ran that right
Or are terminals just totally separate from code
What do you mean? If you run create-next-app, you don't need CRA at all
Can I be using React without next.js?
I started on their site and then got to a step where it told me to use something like next.js or others and so I picked this one just to be able to continue with the tutorial
I also just realized the step says create-next-app instead of create-react-app
you can use vite as an alternative
but just go with either of them if you're now to React.js, it doesn't matter