Problems with navigation

Problems with navigation

I'm having trouble with the navigation of my app when loading a page dynamically.

On my homepage i have a list of links with anchors linking to top level directories.

I have hijacked one of  the links with javascript and done some conditional logic that loads a page dynamically. Depending on the logic results this could be a second or third level directory. 
On first time load of this link the page works fine, however, when I click the JQM back button it takes me to the homepage and all looks well until I try the same link again. 
It's at this point my problems occur.
It looks like JQM has retained the sub directories in the url when it tries to send me to the page. the page loads but the javascript console is filled with 404's.

I have a file structure like this:

index.html
      news/
            index.html
      bins/
            index.html
            detail/
                  index.html

When I load the page for the first time all is well.

But when I click the JQM back button from this page then click the original link again I get these 404 error in the javascript console:

  1. http://10.33.57.156/fdapp.dev/bins/detail/bins/detail/?id=320053911
As you can see it still has bins/detail/ from my previous visit.

I use this piece of JS code from my homepage.js to load the page:
  1. $(document).on("pageshow", "#homepage", function(){
  2. ....
  3. $.mobile.pageContainer.pagecontainer("change", 'bins/detail/?id=' + p);
  4. ....


Has anyone experienced this issue or have some advice for me, that would be great.

Thanks
Steven