Semantic-UI-React icon indicating copy to clipboard operation
Semantic-UI-React copied to clipboard

Usage of react-router-dom and <Tab>

Open alexgrjd opened this issue 7 years ago • 7 comments

I'm trying to add some routing (react-router-dom) to my Semantic-based React app, but for a reason or another, I can't figure out how to integrate it with my Tab component.

I have created a small sandbox here (for those who want to play around with it) with a basic example to demonstrate what I want to achieve. Basically, when the user clicks on one of the three tabs (Authorization, Configs or Config Lists) it should be routed to /authorization/, /configs/ or /config-lists/.

I'm also going to post the code here:

import ReactDOM from "react-dom";
import React, { Component } from "react";
import { Tab } from "semantic-ui-react";

import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";

import "semantic-ui-css/semantic.min.css";

class App extends Component {
  render() {
    const panes = [
      {
        menuItem: "Authentication",
        render: () => <Tab.Pane>Content Authentication</Tab.Pane>
      },
      {
        menuItem: "Config Lists",
        render: () => <Tab.Pane>Content Config Lists</Tab.Pane>
      },
      {
        menuItem: "Configs",
        render: () => <Tab.Pane>Content Configs</Tab.Pane>
      }
    ];
    return (
      <div className="App" style={{ marginTop: "50px" }}>
        <Tab
          menu={{ fluid: true, vertical: true, tabular: true }}
          panes={panes}
        />
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("root"));

How can I do that, given my vertical tab menu?

alexgrjd avatar Jul 26 '19 07:07 alexgrjd

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

welcome[bot] avatar Jul 26 '19 07:07 welcome[bot]

@alexgrjd I updated your CodeSandbox, please check: https://codesandbox.io/s/react-example-qxb2k

Hope that it's clear now 🐱

layershifter avatar Jul 29 '19 12:07 layershifter

Hi @layershifter, in the example on codesandbox if I try to access one link direct like https://qxb2k.csb.app/auth I get the content of the home page, and both home and Authentication get in the active state, how to fix it?

felipe-mendonca avatar Aug 22 '19 13:08 felipe-mendonca

@felipe-mendonca good catch 👍

I updated that CodeSandbox to fix keys warning and the issue with initial tab. The important change is in defaultActiveIndex.

layershifter avatar Aug 22 '19 13:08 layershifter

Hello @layershifter, there is another issue in example - it breaks when using the back/forward browser buttons.

irvingmoar avatar Oct 11 '19 16:10 irvingmoar

Did anyone figure out why the back/forward browser buttons do not work?

weignerg avatar Apr 16 '20 16:04 weignerg

Found a fix with this: https://codesandbox.io/s/react-example-5jtuo?file=/index.js

weignerg avatar Apr 24 '20 16:04 weignerg