dremme
dremme

Reputation: 769

Very Simple Routing on One page website

I'm developing a simple one page website, where the pages scroll horizontally using the scrollTo() javascript library. I have a home / about / contact page. I was wondering if there was a way to still use some form of URL routing like www.example.com/about, to get the about page, and would get updated in the browser when the page was clicked in the navigation.

Upvotes: 0

Views: 233

Answers (2)

Chris Sobolewski
Chris Sobolewski

Reputation: 12945

Your easiest bet is going to be to use hashes. i.e. www.example.com/#about

You can then use window.history (more reading) in order to change the URL without a page reload. Specifically, you will be looking for history.pushState() or history.replaceState()

Depending on what browser support you need, you might need something like History.js to fall back in IE.

Upvotes: 2

Eric Frick
Eric Frick

Reputation: 857

You could load the page with Ajax

Upvotes: 0

Related Questions