Question

let's say that I have two "pages" (endpoints) on a chaplin.js site

the routes:

match('', 'first_controller#show');
match('second_view', 'second_controller#show');

and two links:

<a href="{{#url "first_controller#show" }}{{/url}}">Go to home</a>
<a href="{{#url "second_controller#show" }}{{/url}}">Go to Second</a>

the generated urls are "correct":

mysite.com/something/     (home)
mysite.com/something/second_view  (second view)

(notice that I'm not on the root of the site). When I start the application at "home" and then click the "Go to second" link i get correctly redirected to the second view, everything gets tendered correctly and the url on the browser changes to mysite.com/something/second_view

But then I cannot refresh the navigator since my webserver will try to reach a second_view folder instead, and I'll get a 404.

What i need is to always generate the urls using a # like in backbone, something like mysite.com/something/#/second_view.

BTW: that last link works but chaplin deletes the # (like a redirect)

Maybe I need to configure something? or change something on the ùrl`helper, I couldn't find anything in the docs. Any Ideas??

Thxs

Was it helpful?

Solution

Backbone itself allows this functionality out of the box, through

Backbone.history.start({pushState: false})

(the default)

You can see the startHistory call here. You just have to pass this options object as a second parameter to initRouter in your Application :

this.initRouter(routes, {pushState: false});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top