Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

reactjs - Is it possible to navigate across different sub-domains or base URLs in same application without refreshing the page in React?

I used react-router for navigation. I used props.history.push(url) but it just appends the provided url in existing url.

Example- current URL of browser - http://my-app1.example.com:3000/about

Action to be performed - navigate to http://my-app2.example.com:3000/contactUs without refreshing the page.

To solve above problem I tried following piece of code.

let url = 'http://my-app2.example.com:3000/contactUs'
props.history.push(url)

Result- Browser URL turns to http://my-app1.example.com:3000/about/http://my-app2.example.com:3000/contactUs

I tried using <Link /> still it didn't worked.

Possible solution is to use <a> tag or use window.location.href = url but it refreshes the page.

Finally, my requirement is to navigate to a url with different sub-domain without refreshing the page in a react web-app.

Could anyone suggest a possible solution for the same.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are pointing to another app - your routing will not work and you will have to refresh the page You can create a routing wrapper app for both apps and render them inside, but without that - it will rerender


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...