larrymyers / react-mini-router

A minimal URL router for React.js
MIT License
282 stars 38 forks source link

search params error on the wechat app #59

Closed medici closed 7 years ago

medici commented 8 years ago

If I get a url like http://www.exmaple.com/home#!/message?=c=c&d=d., and I share it to the wechat app, the app will auto add params to the url like http://www.exmaple.com/home?a=a&b=b#!/message?=c=c&d=d. I will get the params as : {c:'c', d: 'd?a', b: 'b'}, and the process will catch a error. I resovle this question with:

function getInitialPath(component) {
    var path = component.props.path || component.context.path,
        hash,
        url;

    if (!path && detect.canUseDOM) {
        url = urllite(window.location.href);
        if (component.props.history) {
            path = url.pathname + url.search;
        } else if (url.hash) {
            hash = urllite(url.hash.slice(2));
            path = hash.pathname + hash.search;
            if(window.location.search) {
                path = hash.pathname + hash.search + window.location.search.replace('?', '&');
            } else {

            }
        }
    }

    return path || '/';
}

function getInitialPath(component) {
    var path = component.props.path || component.context.path,
        hash,
        url;

    if (!path && detect.canUseDOM) {
        url = urllite(window.location.href);
        if (component.props.history) {
            path = url.pathname + url.search;
        } else if (url.hash) {
            hash = urllite(url.hash.slice(2));
            path = hash.pathname + hash.search;
            if(window.location.search) {
                path = hash.pathname + hash.search + window.location.search.replace('?', '&');
            } else {

            }
        }
    }

    return path || '/';
}
larrymyers commented 8 years ago

If you can submit a pull request with tests to resolve the error I'll happily merge and push an update to NPM.

larrymyers commented 7 years ago

No response from @medici. Closing.