Reputation: 81
I am making a static site with Backbone that will have only one file as an entry point(index.html). I was wondering how to make the site respond to any external url to the site? For example
www.example.com/this_route www.example.com/search
While I do have a router set up now, I can only trigger url changes from within the app:
router.navigate( "to_here" );
But if i type www.example.com/to_here in the url bar of a browser, i get the error: "The requested URL /to_here was not found on this server."
Thanks for any help
Upvotes: 0
Views: 105
Reputation: 461
In Backbone you "catch" the url from the browser when they starts with "#". So, even your Router is something like this:
routes : {
"this_route":"exampleFunction",
"search":"searchFunction"
}
if you want to execute each function depending on the browser url, you have to write www.example.com#this_route or www.example.com#search to fire the functions with Router.js
Upvotes: 1
Reputation: 3702
You need to set up your web server to always respond with index.html
.
I'm using nginx for this purpose with rules below, it always serve index.html for any requests like this localhost:8080/to_here
server {
listen 8080;
server_name localhost;
location / {
root /path/to/folder/with/files;
try_files $uri /index.html;
}
}
Upvotes: 1