如何在不重新加载数据的情况下更改url和LinkTo组件?
想象一个用户可以更改其项目名称的应用程序。当前url包含项目名称,因此必须更新。除了url和链接以外,没有任何东西必须修改(无数据重新加载)
考虑这条主路由:
this.route('routeName', { path: '/:project_name/:param2/:param3' }, function () {
...many sub routes
});replaceURL方法允许更改url:
this.router.location.replaceURL(urlWithNewProjectName)LinkTo使用示例(未指定型号,使用默认值):
{{#LinkTo 'routeName'}}link{{/LinkTo}}例如,以下代码失败:
// this code in the router has no effect on LinkTo in templates.
const params = this.paramsFor(this.routeName);
params.project_name = "newName";LinkTo组件继续以旧的urls为目标。如何更改路由的动态线段默认值?
发布于 2019-10-17 01:36:43
您需要将动态段传递给模板中的LinkTo组件。当这些道具改变时,链接将会更新。有关更多信息,请参阅指南:https://guides.emberjs.com/release/templates/links/#toc_example-for-multiple-segments
https://stackoverflow.com/questions/58328649
复制相似问题