How do I link to other pages from index.html


#1

How do I link to other pages from index.html


#2

Projects in HyperDev aren’t special in any way, so you link to files like you normally would with an anchor tag. So for example in our tutorial project https://hyperdev.com/#!/project/denim-warlock in index.html you’ll see the line “<a href="/exercise1.html">”, that links to another page ‘exercise1.html’ in the same project. You can add new files to your own projects by clicking the ‘+’ sign next to ‘front-end’ in the left-hand side file menu, typing the name and hitting enter.


#3

I tried that but continue to receive the following Cannot GET /NewPage.html error. Is there anything else that needs to be configured? I have tried href="/views/NewPage.html", href="/NewPage.html" etc.

(Yes the html page is created in the project)

Resolved

You need to add routing

  response.sendFile(__dirname + '/views/NewPage.html');
});```

Getting started (HTML can't load JS, CSS or images)
#4

If the pages are under public/NewPage.html and you have express serving static assets with app.use(express.static('public')); then it should “just work”. If your pages are in views or another directory then you’ll need to explicitly create routes for them.

I hope this clears it up :slight_smile:


Getting started (HTML can't load JS, CSS or images)
#5

I ran into the same problem and this Q&A helped me - thanks. I just wanted to point out that by default when you add a page using the ‘+’ sign next to ‘front-end’ in the left-hand side file menu, typing the name and hitting enter, the new page ends up under the views directory, not the public directory. So you need to add the routing to fix the “Cannot GET” error.


#6

express.static was in my server.js file by default, however I still got the GET error. What I didn’t understand was that my pages needed to be saved as public/newpage.html instead views/newpage.html. I’m used to thinking that pages go alongside wherever index.html is, and that’s not true here.

All good now tho’


#7

They don’t have to be in any particular directory, they just have to be in the place you’ve configured them to be in Express. So if you’ve used app.use(express.static('public')) then they’d need to go in the public folder, but you could switch that to be views or root.


#8

Thanks for the clarification Gareth.