-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
115 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
HashRouter as Router, | ||
Routes, | ||
Route, | ||
Navigate, | ||
} from 'react-router-dom'; | ||
import { TabsPage } from './components/Tabs'; | ||
import { App } from './App'; | ||
import { HomePage } from './components/HomePage'; | ||
|
||
export const Root = () => ( | ||
<Router> | ||
<Routes> | ||
<Route path="/" element={<App />}> | ||
<Route index element={<HomePage />} /> | ||
|
||
<Route path="/home" element={<Navigate to="/" replace />} /> | ||
|
||
<Route path="tabs"> | ||
<Route index element={<TabsPage />} /> | ||
<Route path=":tabId" element={<TabsPage />} /> | ||
</Route> | ||
|
||
<Route path="*" element={<h1 className="title">Page not found</h1>} /> | ||
</Route> | ||
</Routes> | ||
</Router> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const HomePage: React.FC = () => { | ||
return ( | ||
<div className="container"> | ||
<h1 className="title">Home page</h1> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Link, useParams } from 'react-router-dom'; | ||
|
||
const tabs = [ | ||
{ id: 'tab-1', title: 'Tab 1', content: 'Some text 1' }, | ||
{ id: 'tab-2', title: 'Tab 2', content: 'Some text 2' }, | ||
{ id: 'tab-3', title: 'Tab 3', content: 'Some text 3' }, | ||
]; | ||
|
||
export const TabsPage: React.FC = () => { | ||
const { tabId } = useParams(); | ||
const selectedTab = tabs.find(tab => tab.id === tabId); | ||
|
||
return ( | ||
<div className="container"> | ||
<h1 className="title">Tabs page</h1> | ||
<div className="tabs is-boxed"> | ||
<ul> | ||
{tabs.map(tab => ( | ||
<li | ||
data-cy="Tab" | ||
className={tabId === tab.id ? 'is-active' : ''} | ||
key={tab.id} | ||
> | ||
<Link to={`/tabs/${tab.id}`}>{tab.title}</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
|
||
{selectedTab ? ( | ||
<div className="block" data-cy="TabContent"> | ||
{selectedTab.content} | ||
</div> | ||
) : ( | ||
<div className="block" data-cy="TabContent"> | ||
Please select a tab | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { HashRouter } from 'react-router-dom'; | ||
import { App } from './App'; | ||
import { Root } from './Root'; | ||
|
||
createRoot(document.getElementById('root') as HTMLElement).render( | ||
<HashRouter> | ||
<App /> | ||
</HashRouter>, | ||
); | ||
const conteiner = document.getElementById('root') as HTMLElement; | ||
|
||
createRoot(conteiner).render(<Root />); |