Remove URL params on routing

落爺英雄遲暮 提交于 2019-12-11 09:59:50

问题


I am calling a view passing url parameters to perform specific custom actions. Once, these actions have been processed, I would like to use the router to move to another page but removing the url parameters first.

To be more specific:

Link containing url parameters leads to main page as its route has an empty pattern.

example.com/?urlParam1=Test&urlParam2=Boum

Once the controller has processed the request, I am using the router to nav to another view by calling

getRouter().navTo("ViewX", {}, false)

The url in the browser changes to

example.com/?urlParam1=Test&urlParam2=Boum/#/ViewX

The url parameters are still visible. Any chance to remove them?

Cheers


回答1:


From what I understand from your question you have lets say 2 routes and something like this

routes : [ {
                pattern : "Val1",
                name : "Main",
                view : "Main",
                viewId : "Start"

            },{
                pattern : "Val2",
                name : "Next",
                view : "Next",
                viewId : "Start1"

            } ]

Now you invoke the route "Main" and your URL will be something like
http://applicationurl:port/ProjectName#Val1
and from here you invoke route Next then system will automatically change the url to
http://applicationurl:port/ProjectName#Val2
This is supported out of the box by SAPUI5 routing . Is there something different you want to achieve?

EDIT : Updated Answer
Nope not from the current view.
But i can suggest a workaround. Have one more route to the same view without the parameters of your concern. Now you can call the route after the action is performed leading to same view being loaded.
Couple of points to remember

  1. Be careful with the routes , they should not conflict.
  2. The same view is loaded again leading to routeMatched events being called and needs to handled carefully.

As a side note the routes are meant for Bookmarking and addressable feature. I would suggest you think about handling the action via the EventBus in SAPUI5.



来源:https://stackoverflow.com/questions/32922199/remove-url-params-on-routing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!