Ember, change current url and LinkTo targets without reloading data

為{幸葍}努か 提交于 2019-12-13 03:36:49

问题


How to change an url and the LinkTo components without reloading data?

Figure an app where a user can change the name of his project. The current url contains the project name, so it must be updated. Nothing excepts the url and the links must be modified (no data reload)

Consider this main route:

this.route('routeName', { path: '/:project_name/:param2/:param3' }, function () {
  ...many sub routes
});

The replaceURL method allow to change the url:

this.router.location.replaceURL(urlWithNewProjectName)

Example of LinkTo usage (no model is specified, default values are used):

{{#LinkTo 'routeName'}}link{{/LinkTo}}

For example the following fails:

// this code in the router has no effect on LinkTo in templates.
const params = this.paramsFor(this.routeName);
params.project_name = "newName";

LinkTo components continue to target old urls. How to change a dynamic segment default value for a route?


回答1:


You need to pass the dynamic segments to the LinkTo component in the template. When those props change, the link will update. See the guides for more info starting here: https://guides.emberjs.com/release/templates/links/#toc_example-for-multiple-segments



来源:https://stackoverflow.com/questions/58328649/ember-change-current-url-and-linkto-targets-without-reloading-data

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