Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chid links created using page-href seem wrong #168

Open
manzanotti opened this issue Mar 5, 2014 · 0 comments
Open

Chid links created using page-href seem wrong #168

manzanotti opened this issue Mar 5, 2014 · 0 comments

Comments

@manzanotti
Copy link
Contributor

The jsFiddle I created for issue 167 also displays another issue, that of child page links created when using the page-href binding.

If you have a page, call it listing, which has a querystring parameter called testId, and it has two child pages, call them child1 and child2, if you use page-href to generate the link to the children, like this:

<a data-bind="page-href: 'child1'">Go To Child1 Page</a>
<a data-bind="page-href: 'child2'">Go To Child2 Page</a>

then the links generated will be:

/#listing?testId=1/child1
/#listing?testId=1/child2

I would expect the links to be:

/#listing/child1?testId=1
/#listing/child2?testId=1

as that seems the more natural way to do it to me. I'd also hazard a guess that the current method would result in the testId querystring parameter having a value of 1/child1, so if that child page had a withOnshow method that relied on the querystring parameter, it wouldn't work.

I've also tried adding params to the page route:

<a data-bind="page-href: { path: 'child1', params: { testId: testId() }">Go To Child1 Page</a>
<a data-bind="page-href: { path: 'child1', params: { testId: testId() }">Go To Child1 Page</a>

and this is, if anything, worse:

/#listing?testId=1/child1?testId=1
/#listing?testId=1/child2?testId=1

It seems that the issue is that the querystring parameter should be stripped out of the generated route, and if you want it put back in, then use the params option.

I've managed to get it to initially work by adding to the p.path method:

var fullRoute = me.getFullRoute()();
var parentPath = fullRoute.slice(0, fullRoute.length - parentsToTrim).join('/');

var querystring = '';
var querystringStart = parentPath.indexOf('?');
if (querystringStart !== -1) {
    var nextSlash = parentPath.indexOf('/', querystringStart);
    if (nextSlash !== -1) {
        querystring = parentPath.slice(querystringStart, nextSlash);
        parentPath = parentPath.replace(querystring, '');
    } else {
        querystring = parentPath.slice(querystringStart);
        parentPath = parentPath.replace(querystring, '');
    }
}

var fullPathWithoutHash = (parentPath === '' ? '' : parentPath + '/') + p;

As I said, this does produce the correct links in the page. Can you think of any potential pitfalls with this approach?

I've updated the jsFiddle to have two links: http://jsfiddle.net/ry4UK/4/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant