0

Hi guys so I'm trying to use button in my react-bootstrap app and what that button do is everytime user click the button it will redirect the user to another page of the web-app. But for some reason it didn't work, can anyone help me please ? my router already work for other components such as header, footer, etc. But it didn't work for the Button.

Here's my code:

            <Container fluid>
                <Row className="Aboutus">
                    <Col sm={12} lg={6}>
                        <h1>About Us</h1>
                        <hr style={{border:'2px solid', color:'#10255A', width:'25.7%'}}></hr>
                        <p>The hotel itself possess a trendy design with attention to comfort, 
                           quality and value based accommodation.
                        </p>
                        <button as={Link} to={"/Room"}>See Room</button>
                    </Col>
                    <Col sm={12} lg={6}>
                        <img src="#"></img>
                    </Col>
                </Row>
            </Container>

3 Answers 3

1

You would need to use bootstrap <Button> instead of native HTML <button> for that and change href instead of to:

<Button as={Link} href={"/Room"}>
  See Room
</Button>;

Live Example:

Edit React bootstrap demo (forked)

You will need to open sandbox URL in another tab to see url change

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

5 Comments

Hi thanks for your help. If I use this method can I change the style of my button to my preference ? how can I do it in my css ?
You surely can, you can use className or styles object to the Button itself to style your button just like a native HTML button
I updated some styles for the button inside the codesanbox, you can check it there for better understanding. I used both className and styles object.
Hi, I tried it already but it didn't work, when I try to inspect the element the button contains the "btn btn-primary" even though I didn't write it on my class. How can I remove it ?
It's a predefined class when you use the Button component from bootstrap. If you don't want to use it, then pick a few other classes from here
0

Because you are using normal button, not Button in react-bootstrap.

Just update it

<Button as={Link} to={"/Room"}>See Room</Button>

Comments

0

Another option and just to take advantage of the native link component without using the Button component, is to use the bootstrap classes(which support styling a tags as a button):

<Link to="/Room" className="btn btn-primary">
 See Room
</Link>

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.