0

If I am using window.location.href but it is giving me page reloading experience. How can i prevent reloading and redirect to new URL(path from navigate to URL)

function App(){

useEffect(()={retreiveCategoryLis();})

const retreiveCategoryLis= ()={//axios call to get the category List}

 const navigateToURL = (category) =>
    {
        const path = 'http://localhost:4200/Categories?categoryName='+category;
        alert(path);
        //window.location.href=path
        
    }

 return(
    <div className="categoriesContainer">
        {categoryList && categoryList.map((category) => (
            <div key={Math.random()} className='categoryItem' onClick={()=> navigateToURL(category)}>
            <img key={Math.random()} src={getCategoryImage(category)} alt=""></img>
            <p key={Math.random()}> {category}</p>
        </div>
        )
        )}
    </div>
}

1

1 Answer 1

2

ok since you use react, you can use a library that called react-router-dom.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.