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

让路由支持传参 #547

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

让路由支持传参 #547

wants to merge 1 commit into from

Conversation

maicong
Copy link

@maicong maicong commented Mar 30, 2016

Util.getUrlFragment 取到的是 # 后面的部分,如果使用 ? 传递参数的话会报错。

修改如下:
1、优化 getUrlFragment 判断,如果存在 ? 就截取掉
2、新增 getUrlSearch 函数,以对象形式返回传递的所有参数,可通过 $.router.$args.search 调用
3、给 $.router 对象加上 $args 属性,返回的是 Util.toUrlObject(currentUrl) 的结果

@liunian
Copy link
Contributor

liunian commented Apr 12, 2016

3 直接保存在 $.router 中会有问题,这样只是初始化时候的值,但切换到别的页面时不会变更。

更想了解下的是,路由参数是具体是需要配合怎样的使用场景呢?使用的时候是希望如何使用呢?不知道使用常规 url 的查询参数(path?a=b&c=d#hash)是否可以满足需求呢?

@maicong
Copy link
Author

maicong commented Apr 12, 2016

@liunian path#hash?a=b&c=d 放在 hash 后面才能匹配到,放前面就是 location.search

@Mickey-
Copy link
Contributor

Mickey- commented Apr 18, 2016

目前还是不建议 path#hash?a=b&c=d 这种方式使用,然后在框架里硬解码匹配,会为面向未来的使用场景中增加一些不可控的风险。

@maicong
Copy link
Author

maicong commented Apr 19, 2016

@Mickey- 这只是个临时方案,还是希望路由可以支持传递参数!

@heboliufengjie
Copy link

目前我参与的开发中面临路由传参的需求,且比较成熟的路由(比如angular的ui-route)传参及获取对应的参数十分方便,是个趋势

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

Successfully merging this pull request may close these issues.

4 participants