Nav Bar links has an error message every time I'm trying to use them

Hello! This may be really basic (and I’m sorry if it is) but I’m experiencing some issues with the links in my nav bar facing an error every time I click them. Below is the code, the error message is
“{“message”:“Route GET:/learn not found”,“error”:“Not Found”,“statusCode”:404}”

image

Hi @unofficialwsc and welcome to the forum!

It sounds like your project has a server, like it’s based on Express or Fastify. Probably in your project there is a server.js file right?

In those projects you need to set up the “routes” (URLs) that your project is going to handle. Can you post some of your server.js file?

If you don’t need a backend server to save/retrieve dynamic data, you could base your project on ~glitch-blank-website instead (find all the starter kits here: https://glitch.com/create-project), then your links will work in the simple way I think you’re expecting.

Hope it helps, let us know how you get on

2 Likes

Hello @SteGriff! Thank you for your help!
This is the code from the server.js file (do tell me if you need more/something else, I can only post one image in one reply since I’m a new user):

I used one of the templates of glitch (as you can probably tell from the leftovers from the color generator form I can’t remove without breaking the website). I’m unsure if we do or don’t need a backend server since this is for showing a data science project and you can probably tell I’m a beginner at JS.

Again, thank you for helping!

1 Like

Ok, good explanation.

Since it’s not super clear whether or not you’ll need Fastify or not, let’s just carry on as if you do :slight_smile:

Basically, for each page, you can add a route like this:

fastify.get("/learn", function(request, reply) {
  reply.view("/src/pages/learn.hbs");
}

That’s assuming you’ve already made a handlebars file for your learn page. If you’ve made plain HTML instead… I think it will still work with /src/pages/learn.html? Dunno, haven’t tried it :slight_smile:

There is probably a neat way of not having to write a handler for every “normal” static page… like you could iterate over them… maybe someone else can comment.

Hope it helps :seedling:

1 Like