Navigate to new url from SPFX in Sharepoint online

%3CLINGO-SUB%20id%3D%22lingo-sub-2210149%22%20slang%3D%22en-US%22%3ENavigate%20to%20new%20url%20from%20SPFX%20in%20Sharepoint%20online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2210149%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22votecell%20post-layout--left%22%3E%3CDIV%20class%3D%22js-voting-container%20grid%20jc-center%20fd-column%20ai-stretch%20gs4%20fc-black-200%22%3E%3CDIV%20class%3D%22js-vote-count%20grid--cell%20fc-black-500%20fs-title%20grid%20fd-column%20ai-center%22%3E%3CSPAN%3EI%20have%20a%20dropdown%20in%20SPFX%20webpart%20in%20sharepoint%20online.%20In%20that%20dropdown%2C%20onchange%2C%20I%20am%20constructing%20a%20url%20with%20%23%20tag.%20E.x.%20https%3A%2F%2Fsharepointonine%2Fdefault.aspx%232349-234234-23434%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22postcell%20post-layout--right%22%3E%3CDIV%20class%3D%22s-prose%20js-post-body%22%3E%3CP%3EI%20need%20to%20navigate%20to%20this%20new%20url.%20I%20am%20not%20sure%20how%20to%20accomplish%20things.%20I%20have%20tried%3A%3C%2FP%3E%3CPRE%3Ewindow.location%20%3D%20url%20%2F%2FGives%20error%20that%20string%20is%20not%20assignable%20to%20Location%0Awindow.location.href%3D%20url%2F%2Fdoes%20not%20reload%20the%20page%0Awindow.open(url%2C%20%22_self%22)%2F%2Fdoes%20not%20reload%20the%20page%0Awindow.location.assign(url)%3B%2F%2Fdoes%20not%20reload%20the%20page%0A%20window.location.replace(url)%3B%2F%2Fdoes%20not%20reload%20the%20page%3C%2FPRE%3E%3CP%3EAny%20help%3F%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2210149%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESPFx%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor
I have a dropdown in SPFX webpart in sharepoint online. In that dropdown, onchange, I am constructing a url with # tag. E.x. https://sharepointonine/default.aspx#2349-234234-23434

I need to navigate to this new url. I am not sure how to accomplish things. I have tried:

window.location = url //Gives error that string is not assignable to Location
window.location.href= url//does not reload the page
window.open(url, "_self")//does not reload the page
window.location.assign(url);//does not reload the page
 window.location.replace(url);//does not reload the page

Any help?

1 Reply

Using query parameters instead of url fragment has resolved the issue . With that , window.location.href will also work