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

路径参数解析的问题 #80

Closed
lkiarest opened this issue Jul 21, 2015 · 2 comments
Closed

路径参数解析的问题 #80

lkiarest opened this issue Jul 21, 2015 · 2 comments

Comments

@lkiarest
Copy link

主要表现如下:
在状态配置里使用 /book/{id} 这种格式定义一个view,
然后用" /book/1" 访问是正常的,但是使用 "/book/0" 访问的话就会解析成"/book".

经过debug发现是mmRouter.js里的参数判断有问题:

        urlFormate: function(url, params, query) {
            var query = query ? queryToString(query) : "",
                hash = url.replace(placeholder, function(mat) {
                    var key = mat.replace(/[\{\}]/g, '').split(":")
                    console.log(key);
                    key = key[0] ? key[0] : key[1]
                    //return params[key] || ''   // 这个地方判断的时候param的值如果为 0或者false什么的,就会被过滤掉,改成下面一行就可以了
                    return params[key] !== undefined ? params[key] : ''
                }).replace(/^\//g, '')

            console.log("after url formate");
            console.log("hash:" + hash);
            console.log("query:" + query);
            return {
                path: hash,
                query: query
            }
        },
@IndexXuan
Copy link

也发现了这个。。。例子里都是用没有就是0来兼容的。。。建议修复,我的项目后来改为了复杂参数规避了这个问题。

@RubyLouvre
Copy link
Owner

谢谢,已修

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

3 participants