Transition from one route to another with a different model in Emberjs

后端 未结 2 1192
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-23 00:33

I have a search page where we are getting different types of search results. In the list of search results I would like to use

{{#linkTo \'someResources.someRes         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-23 01:18

    Since the problem is that I want a full reload of the model when doing the transition using linkTo won't work since that is using the model given to it. The solution to the problem is actually quite simple, just use a regular html a-tag instead. What I ended up doing was this:

    {{someTextProperty}}
    

    The property somePropertyInYourModel is a property containing the url to the new page. If the url is in the ember routes it will be as if you where typing that address in the address bar and pressing enter, but without the full reload of the page.

    I think this is something that could be improved in ember, it would be much nicer if I could write something like:

    {{#linkToRoute "resourceA.routeB" params="val1,val2,val3"}}Go here{{/linkToRoute}}
    

    given I have this routes set up:

    App.Router.map(function() {
        this.resource("resourceA", {{path: "/resourceA"}}, function() {
            this.route("routeB", {{path: "/:prop1/:prop2/:prop3");
        }
    });
    

    I would like to get:

    Go here
    

    The order of the val1,val2,val3 matters, if the order is changed they should also be changed in the final url.

提交回复
热议问题