Sammy.js 404 on the root path

I am trying to identify some routes using sammy.js, here is my code:

$.sammy("#main_content", function() { this.get("#!/about", function() { // Code }); this.get("#!/", function() { // Code }); }).run(); 

If I have a site www.mywebsite.com, I always get a 404 error. I tried to put an empty route like this.get("", function() {}); , and it seems to work to prevent 404 errors, but then none of my regular links on the page work. How can i fix this?

+7
source share
2 answers

It simply failed to override:

this.notFound = function () {// do something}

You can see it here: https://github.com/quirkey/sammy/issues/67

+4
source

To process an original request that does not contain a hash, use the empty route that you specified at the bottom of your route list

 /* Get Home view for empty hash URLs */ this.get("", function () { this.app.runRoute("get", "#Home"); }); 

For normal links on your site to work, that is, links to binary files that AJAX requests do not process, configure your anchor elements using a hash route and parameters as follows (the code uses Razor syntax)

 <a href="@Url.Content("#Reporting/Excel/" + Model.Report.Type.ToString() + "/" + Model.Report.Audience.ToString() + "/" + Model.Report.UnitID.ToString() + "/" + Model.Report.DepartmentID.ToString())">Download Excel version</a> 

Now create a route for Sammy to send to the actual URL

 /* Reporting Excel requests */ this.get("#Reporting/Excel/:type/:audience/:unitID/:departmentID", function () { location.assign("Report/Excel?" + "Type=" + this.params.type + "&" + "Audience=" + this.params.audience + "&" + "UnitID=" + this.params.unitID + "&" + "DepartmentID=" + this.params.departmentID ); }); 
+7
source

All Articles