Question

I am making an application using sammyJS and node.js.The problem is : according to the docs, I can put a # or not at the begining of the routes (/#/myroute/). All my app was builded w/o the sharp, and now I want to add arguments to the routes (:arg0), I cant unless I add the # at the beginning. It is 'ugly', and worst, I have to refactor all the app.

 self.get(/\/browse\/(.*)/, function(context) {}); // Get 404 when accessing /browse/date
 self.get(/\#\/browse\/(.*)/, function(context) {}); // Works when accessing #/browse/date

So why I have to put that # and is there a way to remove it.

Was it helpful?

Solution

This is something that your Node server has to support as well: Sammy will only get to handle the change in URL when a user navigates to /browse/something whilst the Sammy app is already active, but when it's not (for instance, you're reloading the page or opening it directly in your browser) the request is handled by Node, and it needs to know how to process those requests.

If you're using Express, you may have a route looking like this:

app.get('/browse/', ...);

Try changing that to:

app.get('/browse/*', ...);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top