Javascript 是否可以在不重新加载页面的情况下修改url?
在我的应用程序中,在某一点上,我从回调中收到一些查询参数。我需要将它们存储到redux store中,在重定向之后,页面上的用户需要修改URL,而无需重新加载页面 实际上我使用的是Javascript 是否可以在不重新加载页面的情况下修改url?,javascript,html,reactjs,redux,react-redux,Javascript,Html,Reactjs,Redux,React Redux,在我的应用程序中,在某一点上,我从回调中收到一些查询参数。我需要将它们存储到redux store中,在重定向之后,页面上的用户需要修改URL,而无需重新加载页面 实际上我使用的是history.replaceState。它可以工作,但如果我转到另一个路由(我的内部路由),它会将实际链接连接到实际链接(已替换)我没有使用redux(使用mobx),但我通常使用下面的代码更新url而不刷新页面 第一部分侦听第二个代码段@computed get url()中的url,并在url更改时自动更新url
history.replaceState
。它可以工作,但如果我转到另一个路由(我的内部路由),它会将实际链接连接到实际链接(已替换)我没有使用redux(使用mobx),但我通常使用下面的代码更新url而不刷新页面
第一部分侦听第二个代码段@computed get url()
中的url,并在url更改时自动更新url
autorun(() => {
const path = store.navigation.url
if (path !== window.location.pathname) {
window.history.pushState(null, null, path)
}
})
这一部分只是想弄清楚在url中放什么,例如:按下一个选项卡,将@observable view:view=“home”
更改为@observable view:view=“hooks”
url将从site.com更改为site.com/hooks
@observable view: View = "home"
......
@computed get url() {
switch (this.view) {
case "home":
return '/'
case "hooks":
return 'hooks'
case "fields":
return "fields"
case "validation":
return 'validation'
case "reusable":
return 'reusable'
case "profile":
return 'profile'
case "userProfile":
return 'userProfile'
case "review":
return 'review'
}
}
我没有使用redux(使用mobx),但我通常使用下面的代码来更新url,而不刷新页面
第一部分侦听第二个代码段@computed get url()
中的url,并在url更改时自动更新url
autorun(() => {
const path = store.navigation.url
if (path !== window.location.pathname) {
window.history.pushState(null, null, path)
}
})
这一部分只是想弄清楚在url中放什么,例如:按下一个选项卡,将@observable view:view=“home”
更改为@observable view:view=“hooks”
url将从site.com更改为site.com/hooks
@observable view: View = "home"
......
@computed get url() {
switch (this.view) {
case "home":
return '/'
case "hooks":
return 'hooks'
case "fields":
return "fields"
case "validation":
return 'validation'
case "reusable":
return 'reusable'
case "profile":
return 'profile'
case "userProfile":
return 'userProfile'
case "review":
return 'review'
}
}
函数
reload
中的代码是静态的,即仅当您调用它时才会执行。如果在调用它时,窗口的宽度不超过1000px,那么您的函数将不会执行任何操作
您需要收听以下活动:
window.location.replace(window.location)
函数reload
中的代码是静态的,即仅当您调用它时才会执行。如果在调用它时,窗口的宽度不超过1000px,那么您的函数将不会执行任何操作
您需要收听以下活动:
window.location.replace(window.location)
是的,我在我的应用程序中使用它进行内部路由,但一旦我直接转到pat,我就会丢失历史记录并返回或前进。所以我正在尝试寻找另一种解决方案。是的,我在我的应用程序中使用它进行内部路由,但一旦我直接转到pat,我就会丢失历史记录并返回或前进。所以我试图找到另一个解决方案。window.location.replace(“index.html”);另外,您可以使用它。window.location.replace(“index.html”);另一方面,你可以使用它。