打开模态并更新URL而不重新加载主页
我具有primeReAteAct DataTable(它是单独的组件 InvoIcetable ,它是许多列的另一个较大的Copmonent AccountDetails )的一部分 - 每个列都有许多列 - 每个列都有选择模式和按钮。当我单击按钮时,它将打开新的模式并更改URL。 主页的URL( AccountDetails )是客户/CustomerCode ,当我打开模态时(我单击 InvoIcetable的图标)它成为客户/customercode/invoiceNumber/changelog 。
问题是,当我选择任何发票并打开模式时,主页会刷新,并且未选择所选的发票。
这些是我使用的方法:
openHistoryModal = (rowData, e) => {
e.stopPropagation();
this.props.history.push(`/customers/${customerCode}/number/changelog`);
};
discardHistoryModal = (e) => {
this.props.history.push(`/customers/${customerCode}`);
};
我尝试使用histor.replace和window.history.thistorate,但结果是相同的。我只使用类组件。
我也有以下路线:
<ProtectedRoute
path="/customers/:customerCode/"
component={(props: any) => <AccountDetails {...props} />}
authority={[userRoles.user]}
feature={"Collection module"}
rootStore={this.props.rootStore}
exact={true}
/>
<ProtectedRoute
path="/customers/:customerCode/:number/changelog"
component={(props: any) => <AccountDetails {...props} />}
authority={
[userRoles.userAudit.toString()] || [userRoles.admin]
}
feature={"Collection module"}
rootStore={this.props.rootStore}
exact={true}
/>
这些是preectedRoute组件中的方法:
checkAuthority = (roles) =>{
return this.props.rootStore.userStore.hasRoles(roles)
}
checkFeature = () => {
let featureActive: boolean = false;
const foundFeature =
this.props.rootStore.managementStore.featureFlags.filter(
(flag: { name: string; value: string; type: string }) =>
flag.name === this.props.feature && flag.value === "true"
);
if (
(foundFeature && foundFeature.length > 0) ||
this.props.feature === "alwaysActive"
) {
featureActive = true;
}
return featureActive
};
render() {
const { component: Component, ...props } = this.props;
return (
<Route
{...props}
render={(props) =>
this.checkAuthority(this.props.authority) && this.checkFeature() ? (
<Component {...props} rootStore={this.props.rootStore} />
) : (
<Redirect to='/404'></Redirect>
)
}
exact={this.props.exact}
/>
);
如果您能给我一些想法并帮助我,我将非常感激!
I have primereact datatable (it is separate component InvoiceTable and it is part from another bigger copmonent AccountDetails) with many columns- every column has a selection mode and a button. When I click the button, it opens a new modal and changes the url.
The url of the main page (AccountDetails) is customers/customerCode and when I open the modal (I click on the icon from the InvoiceTable) it becomes customers/customerCode/invoiceNumber/changelog.
The issue is that when I select any invoices and open the modal, the main page is refreshed and the selected invoices are unselected.
These are the methods which I use:
openHistoryModal = (rowData, e) => {
e.stopPropagation();
this.props.history.push(`/customers/${customerCode}/number/changelog`);
};
discardHistoryModal = (e) => {
this.props.history.push(`/customers/${customerCode}`);
};
I tried with history.replace and window.history.replaceState but the result is the same. I use only class components.
I have the following Routes as well:
<ProtectedRoute
path="/customers/:customerCode/"
component={(props: any) => <AccountDetails {...props} />}
authority={[userRoles.user]}
feature={"Collection module"}
rootStore={this.props.rootStore}
exact={true}
/>
<ProtectedRoute
path="/customers/:customerCode/:number/changelog"
component={(props: any) => <AccountDetails {...props} />}
authority={
[userRoles.userAudit.toString()] || [userRoles.admin]
}
feature={"Collection module"}
rootStore={this.props.rootStore}
exact={true}
/>
These are the methods in the ProtectedRoute component:
checkAuthority = (roles) =>{
return this.props.rootStore.userStore.hasRoles(roles)
}
checkFeature = () => {
let featureActive: boolean = false;
const foundFeature =
this.props.rootStore.managementStore.featureFlags.filter(
(flag: { name: string; value: string; type: string }) =>
flag.name === this.props.feature && flag.value === "true"
);
if (
(foundFeature && foundFeature.length > 0) ||
this.props.feature === "alwaysActive"
) {
featureActive = true;
}
return featureActive
};
render() {
const { component: Component, ...props } = this.props;
return (
<Route
{...props}
render={(props) =>
this.checkAuthority(this.props.authority) && this.checkFeature() ? (
<Component {...props} rootStore={this.props.rootStore} />
) : (
<Redirect to='/404'></Redirect>
)
}
exact={this.props.exact}
/>
);
I will be very grateful if you could give me some ideas and help me out!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论