Just as a preface, I have checked stackoverlow's material UI section.
I'm having trouble integrating React routing's Link Tag with Material UI Tabs.
I've tried putting the Link in the Tab. The result is that there are no errors, but upon clicking the Tabs, the url does not change.
<Tabs
value={this.state.value}
onChange={this.handleChange}
indicatorColor="primary"
textColor="primary"
centered
>
<Tab className={classes.tabby}label="Facebook" >
<Link to='/Facebook'>Facebook</Link>
</Tab>
<Tab className={classes.tabby}label="LinkedIn" >
<Link to='/LinkedIn'>LinkedIn</Link>
</Tab>
<Tab className={classes.tabby}label="Twitter" >
<Link to='/Twitter'>Twitter</Link>
</Tab>
</Tabs>
I've also tried passing the Link in using the children property. This doesn't change the url either, nor does cause any errors.
<Tab className={classes.tabby}label="Facebook" children={<Link to="/Facebook" />}></Tab>
<Tab className={classes.tabby}label="LinkedIn" children={<Link to="/LinkedIn" />}/>
<Tab className={classes.tabby}label="Twitter" children={<Link to="/Twitter" />}/>
Finally wrapping Tab in Link as given below breaks the tab bar component and returns an error of:
<Link to='/Facebook'>Facebook
<Tab className={classes.tabby}label="Facebook" />
</Link>
warning.js:36 Warning: Unknown props `fullWidth`, `textColor` on <a> tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop
in a (created by Link)
in Link (created by PlatformTabs)
"material-ui": "^1.0.0-beta.10",
"material-ui-icons": "^1.0.0-beta.5",
"react": "^15.6.1",
"react-dom": "^15.6.1",
Chrome: Version 61.0.3163.79 (Official Build) (64-bit)
"react-router-dom": "^4.2.2",
Do something like:
<Tab label="Facebook" component={Link} to="/facebook" />
Current Tab and Link Code:
//PLATFORMTABS.JS
<Tabs
value={this.state.value}
onChange={this.handleChange}
indicatorColor="primary"
textColor="primary"
centered
>
<Tab className={classes.tabby} label="Facebook" component={Link} to="/Facebook" />
<Tab className={classes.tabby} label="LinkedIn" component={Link} to="/LinkedIn"/>
<Tab className={classes.tabby} label="Twitter" component={Link} to="/Twitter"/>
</Tabs>
My route code looks like this.
return(
<div style={styles.background}>
<div style={styles.dayContainer}>
<TopBar/>
<PlatformTabs/>
<Switch>
<Route path='/Facebook' component={FacebookPosts}/>
<Route path='/LinkedIn' component={LinkedInPosts}/>
<Route path='/Twitter' component={TwitterPosts}/>
</Switch>
<SimpleLineChart/>
</div>
</div>
)
But, once I load the page, this error shows up.
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of `Route`.
in Route (created by PostVisual)
in Switch (created by PostVisual)
in div (created by PostVisual)
in div (created by PostVisual)
in PostVisual (created by App)
in div (created by App)
in App
in Router (created by BrowserRouter)
in BrowserRouter
in AppContainer
in div
My components that the routes are supposed to render are not there either and if I click any tab, this error is given.
ReactCompositeComponent.js:744 Uncaught TypeError: Cannot read property '_currentElement' of null
at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js:744)
at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js:723)
at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js:644)
at ReactCompositeComponentWrapper.receiveComponent (ReactCompositeComponent.js:546)
at Object.receiveComponent (ReactReconciler.js:124)
at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js:753)
at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js:723)
at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js:644)
at ReactCompositeComponentWrapper.receiveComponent (ReactCompositeComponent.js:546)
at Object.receiveComponent (ReactReconciler.js:124)
Nevermind, I changed how I was importing and it's working. Thanks!
@davidfufu perhaps you could elaborate how you fixed this?
I believe I switched to "export default Component". Before, I was using multiple defaults from one file and destructuring them when importing like "import { Component1, Component2}".
<Tab label="Facebook" component={Link} to="/facebook" />
, material UI
doesn't have property to
@evalcraciun Link
has a to
property.
I got this error message
Type聽'typeof聽Link'聽is聽not聽assignable聽to聽type聽'"object"聽|聽"a"聽|聽"abbr"聽|聽"address"聽|聽"area"聽|聽"article"聽|聽"aside"聽|聽"audio"聽|聽"b"聽|聽"base"聽|聽"bdi"聽|聽"bdo"聽|聽"big"聽|聽"blockquote"聽|聽"body"聽|聽"br"聽|聽"button"聽|聽"canvas"聽|聽"caption"聽|聽...聽96聽more聽...聽|聽undefined'. 聽聽Type聽'typeof聽Link'聽is聽not聽assignable聽to聽type聽'ComponentClass
'. 聽聽聽聽Types聽of聽parameters聽'props'聽and聽'props'聽are聽incompatible. 聽聽聽聽聽聽Property聽'to'聽is聽missing聽in聽type聽'ButtonBaseProps'聽but聽required聽in聽type聽'Readonly '.
@129emma #14170
This method makes it so that when a tab is pressed, the link hover text stays visible at the bottom of the page until you click elsewhere or select a different tab.
What about Next.js Link
component? It doesn't have a to
property but a href
one.
How could I add a link to a tab
using the Next.js Link
component?
Edit:
@oliviertassinari , the solution you propose (i.e. <Tab label="Facebook" component={Link} to="/facebook" />
) doesn't seem to work anymore. The doc mentions a "component prop" (here that doesn't exist anymore).
This solution should still be valid: https://material-ui.com/guides/composition/#routing-libraries
Thank you for the answer!
Most helpful comment
Do something like: