๋ฐ์ ๋ผ์ฐํฐ ์ฌ์ฉ ... ์ ํ ๊ตฌ์ฑ ์์๋ฅผ ์ฌ์ฉํ์ฌ SPA ์ ํ ํ์ ์ด๋ฒคํธ๋ฅผ ์์ฑํฉ๋๋ค. ๋ชจ๋ ์ข
๋ฅ์ material-ui ๋ฒํผ์ Link๋ก ๋ํํ๋ฉด Chrome์์๋ ์ ๋๋ก ์๋ํ์ง๋ง Safari์์๋ ์๋ํ์ง ์์ต๋๋ค. Safari์์๋ ํ์ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ์ง ์์ต๋๋ค. ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋ฒํผ ์์ฒด์ ๋ช
์์ ์ธ onTouchTap
ํธ๋ค๋ฌ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด์ง๋ง ์ด๊ฒ์ด ์ผ์ข
์ ๋ฒ๊ทธ๋ผ๊ณ ์๊ฐํฉ๋๋ค.
@mariusk ๋ฐ์ ๋ผ์ฐํฐ์์ Button ๊ตฌ์ฑ ์์๋ก Link ๊ตฌ์ฑ ์์๋ฅผ ์ด๋ป๊ฒ ์ถ๊ฐํ๋์ง ์๋ ค์ฃผ์๊ฒ ์ต๋๊น? ์๋ฅผ ๋ค์ด ๋ค์๊ณผ ๊ฐ์ ์์ ์ ์ํํ๋ฉด ์๋ํ์ง ์์ต๋๋ค.
let editLink = <Link to="editTopic"/>;
<IconButton
linkButton={true}
onTouchTap={editLink}
tooltip="Edit forum">
<i className="material-icons">edit</i>
</IconButton>
linkButton={true}
๋ฅผ ์ถ๊ฐํ๋ฉด href
์์์ ๊ฒฝ๋ก๋ฅผ ์ถ๊ฐํด์ผ ํ์ง๋ง ๋ฐ์ ๋ผ์ฐํฐ ๋งํฌ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ต์ปค ํ๊ทธ๋ฅผ ์์ฑํฉ๋๋ค.
์ค์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
<Link to="/login"><FlatButton onTouchTap={this.clickHandler}>{l.l('no', 'Sign in')}</FlatButton></Link>
onTouchTap ํธ๋ค๋ฌ๊ฐ ์์ผ๋ฉด Chrome์์๋ ์๋ํ์ง๋ง Safari์์๋ ์๋ํ์ง ์์ต๋๋ค. ๋ช
์์ ํธ๋ค๋ฌ(์ด๋ ๋ค์ react-router์ transitionTo(...)
ํธ์ถํจ)๋ฅผ ์ฌ์ฉํ๋ฉด ์ฌํ๋ฆฌ์์๋ ์๋ํฉ๋๋ค.
FlatButton์ด <button />
์์๋ฅผ ์์ฑํ๊ณ <a />
<Link />
๊ฐ <a />
์์๋ฅผ ์์ฑํ๋ค๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์ผ ์ ์์ต๋๋ค. ๋ฐ๋ผ์ ๋ค์์ ๊ฐ๊ฒ ๋ฉ๋๋ค.
<a><button /></a>
๋ด๊ฐ ์๊ฐํ ์ ์๋ ํ ๊ฐ์ง ํด๊ฒฐ์ฑ ์ ์ฌ์ฉ์๊ฐ ์ปจํ ์ด๋ ์์๋ฅผ ์ฌ์ฉ์ ์ ์ํ ์ ์๋๋ก ํ๋ ์์ ์ํ์ ํ์ฉํ๋๋ก ํ์ฅ ๋ฒํผ์ ๋ณ๊ฒฝํ๋ ๊ฒ์ ๋๋ค. ๋ฐ๋ผ์ ๋ค์์ ์ํํ ์ ์์ต๋๋ค.
<FlatButton containerElement={<Link to="/login"/>} />
๋ค๊ฐ ์ณ์; ์์ ๋ด๋ถ์ ๋ฒํผ์ ์ ํจํ html5๊ฐ ์๋๋๋ค. ๋ ๋ค๋ฅธ ๊ฐ๋ฅํ ํด๊ฒฐ์ฑ
์ a
์์( button
์ถ๊ฐ)์ ๋ฒํผ ์คํ์ผ์ ์ฌ์ฉํ ์ ์๋๋ก ํ ๋ค์ className
๋ก ๊ฐ๋จํ๊ฒ ์คํ์ผ์ ์ง์ ํ๋ ๊ฒ์
๋๋ค.
์ค์ ๋ก #846์ ์ฌ์ฉํ๋ฉด ๋ค์์ ์ํํ ์ ์์ต๋๋ค.
<FlatButton>
<Link to="/login/" />
</FlatButton>
๋ฐฉ๊ธ #846์ ํ ์คํธํ์ต๋๋ค. ์คํ์ผ์ด ๊นจ์ง๊ณ (๋ฒํผ ํ ์คํธ๋ ํฐ์ ๋ฐํ์ ํฐ์) ๋งํฌ๊ฐ ํ์ฑํ๋์ง ์์ต๋๋ค(์๋ํ์ง ์์). ํ ์คํธํ ์ค์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
<FlatButton><Link to="/login">{l.l('no', 'Sign in')}</Link></FlatButton>
์์ ๋ฌธ์ (๋ด ์คํ์ผ๋ก ์ธํด ๋ฐ์) ๋ฐ ๋งํฌ๊ฐ ์ฌ์ ํ ์๋ํ์ง ์๋๋ค๋ ์ฌ์ค ์ธ์๋ ํฌ์ปค์ค ๋ฌธ์ ๋ ์์ต๋๋ค. ํฌํจ๋ a
๋งํฌ ์๋ก ๋ง์ฐ์ค๋ฅผ ๊ฐ์ ธ๊ฐ๋ฉด ์ ์ฒด ๋ฒํผ์ด ์๋ ๋งํฌ ๋ถ๋ถ๋ง ๊ฐ์กฐ ํ์๋ฉ๋๋ค.
@mariusk ๋น์ ์ ์ง๊ธ ์ด๊ฒ์ ํ ์ ์์ด์ผ ํฉ๋๋ค:
<FlatButton
containerElement={<Link to="/login" />}
linkButton={true}
label={l.l('no', 'Sign in')}/>
๊ทธ๊ฒ์ ์๋ฒฝํ๊ฒ ๋ณด์ด๊ณ ์๋ํฉ๋๋ค. ๊ฐ์ฌํฉ๋๋ค. ํ๋ฅญํ ์ํ์ ๋๋ค!
์ด ์ต์
์ผ๋ก ์ ํํ๋ฉด EventEmitter ๋ฉ๋ชจ๋ฆฌ ๋์ ๊ฒฝ๊ณ ๊ฐ ํ์๋ฉ๋๋ค. <Link>
์ ํด๋ฆญ ํธ๋ค๋ฌ์ธ์ง ์๋๋ฉด <EnhancedButton>
์ ํด๋ฆญ ํธ๋ค๋ฌ๊ฐ ์ ๋๋ก ์ ๊ฑฐ๋์ง ์๊ณ ์๋์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ์๋ง๋ <Link>
๊ฐ ์ ๋๋ก ๋ง์ดํธ ํด์ ๋์ง ์์์ต๋๊น?
์ด์ linkButton={true}
์์ด๋ ์๋ํ๋ ๊ฒ ๊ฐ์ฃ ? ๋ฒํผ์ Link
๋ํ containerElement
์์ผ๋ฉด <button>
์๋ <a>
์์๋ก ๋ฐ๋๋๋ค.
@hai-cea ์ข์์, thx!
@antoinerousseau ์, <a>
๋ก ์ ํํ๊ณ ํ ์คํ์ผ์ ๊นจ๊ณ ... ์๋ text-align: center
์ค์ ๋ ํ
์คํธ๊ฐ ์ผ์ชฝ์ผ๋ก ๋ณ๊ฒฝ๋์์ต๋๋ค. ์ง๊ธ์ <a>
์์์
๋๋ค.
containerElement๊ฐ ๋ฌธ์ํ๋์ง ์์์ต๋๋ค :(
์ด ์ค์ (์: RaisedButton
width containerElement={<Link to="/register>}
์ CSS ๋ฌธ์ ๊ฐ ์์ต๋๋ค. Ripple ํจ๊ณผ๊ฐ ์ ๋๋ก ์คํ๋์ง ์๊ณ ์์ต๋๋ค. ์ค์ ๋ก ์คํ๋์ง๋ง ์ง์ฐ์ด ๋๋ฌด ์ปค์ ๊ฑฐ์ ๋ณผ ์ ์์ต๋๋ค. ๊ทธ๋ฐ ๋ฒํผ์ ๊ธธ๊ฒ ํญํ์ธ์.) ์ ๋ v0.15.4๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
์๋๋ฅผ ๋์ด๋ ๋ฐฉ๋ฒ์ ๋ํ ํํธ๊ฐ ์์ต๋๊น?
๋ ์ด์ ์๋ํ์ง ์์ต๋๋ค
๊ฒฝ๊ณ : ํ๊ทธ ์ ์ ์ ์๋
linkButton
์ํ์ด ์์ต๋๋ค.
@wzup ๊ทธ๋ฅ linkButton={true}
@wzup linkButton ์ํ ์์ด ์ด์ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑํ๋ฉด ์๋ํด์ผ ํฉ๋๋ค.
<FlatButton
containerElement={<Link to="/login" />}
/>
@ํ์ด-์ธ์ ,
์๋
ํ์ญ๋๊น,
๋ฒํผ ํด๋ฆญ ํ ํ์ํ๋ฉด ์์ ์ฝ๋์์ ๋ก๊ทธ์ธ ํ์ด์ง [๋ชจ๋ฌ ๊ธฐ๋ฅ์ ๋งํจ]์ ํ์
๊ธฐ๋ฅ์ ์ด๋ป๊ฒ ๋ง๋ค ์ ์์ต๋๊น?
๋ฒํ๋ฅผ ์ฉ์ํ์ง๋ง ๋ค์์ ์ฌ์ ํ โโ0.17์์ ๊ฒฝ๊ณ ๋ฅผ ์์ฑํฉ๋๋ค.
<RaisedButton
label="Sign In"
containerElement={<Link to="/login" />}
/>
๋ค์์ ์์ฑํฉ๋๋ค.
๊ฒฝ๊ณ : ํ๊ทธ ์ ์ ์ ์๋ onTouchTap
์ํ์ด ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ https://fb.me/react-unknown-prop๋ฅผ ์ฐธ์กฐ ํ์ญ์์ค.
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์๊ธฐ ๋๋ฌธ์ ์ ์๊ฒ ๋ง๋ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ๊ตฌ์ฑ ์์๋ฅผ ๋ง๋ค์์ต๋๋ค.
import React from 'react';
import {Component, PropTypes} from 'react';
import FlatButton from 'material-ui/FlatButton';
export default class FlatLinkButton extends Component {
static propTypes = {
...FlatButton.propTypes,
to: PropTypes.string.isRequired,
link: PropTypes.func.isRequired,
label: PropTypes.node.isRequired,
};
render() {
const style = Object.assign({
color: 'white',
marginTop: '7px'
}, this.props.style);
const props = {
...this.props,
style,
};
delete props.to;
delete props.link;
const Link = this.props.link;
return (
<Link to={this.props.to}>
<FlatButton {...props}/>
</Link>
);
}
}
์ฉ๋ฒ:
import {Link} from 'react-router';
import FlatLinkButton from './FlatLinkButton';
<FlatLinkButton to="/login" link={Link} label="Login"/>
@MatthewEdge #4670์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํด์ผ ํฉ๋๋ค.
Material UI v1.0.0-alpha20 ์์๋ ์ด๊ฒ์ด ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
<Button color="contrast" containerElement={<Link to="/login" />} linkButton={true} >
Login
</Button>
์๋ ํ์ธ์,
๋์ผํ ๋ฌธ์ , ํ๋กํ ํ์ดํ์ v1.0.0-alpha21์ ์ฌ์ฉํ๊ณ containerElement
์ ์ ์ ์๋ค๋ ๋ฉ์์ง๋ฅผ ๋ฐ์์ต๋๋ค. ๊ทธ๋์ ์์ฑ์ด ์ญ์ ๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๊ณ ์ด ์๋ฃจ์
์ผ๋ก ๋๋ฌ์ต๋๋ค.
<Button raised dense color="primary" onClick={() => this.props.history.push('/project/4711')}>
<i className="fa fa-search fa-on-button" aria-hidden="true" />Search
</Button>
@HerrVoennchen ์ด ์ต์ ๋ฒ์ v1.0.0-beta.3
ํ๋ฉด ๋ค์์ ์ํํ ์ ์์ต๋๋ค.
const LinkWrapper = ({ ...props }) => (
<Link {...props} />
)
๊ทธ๋ฐ ๋ค์ ๋ํผ๋ฅผ ๊ตฌ์ฑ ์์๋ก ์ฌ์ฉํ์ญ์์ค.
<Button to={`/project/${id}`} component={LinkWrapper}>Go</Button>
ํฌ์ธํฐ @HiroAgustin์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ์ด๊ฒ์ v1.0.0-beta.3
์์ ์๋ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
<Button
color="primary"
to={`/projects/${project.id}`}
component={props => <Link {...props}/>}
>View</Button>
@HiroAgustin ๋ฐ @hubgit ์ ์๋ฃจ์
์ ์ฌ์ฉํ๋ 1.0.0-beta.6
์์ ๊ฒฝ๊ณ ๊ฐ ํ์๋ฉ๋๋ค.
๊ฒฝ๊ณ : Material-UI: ๊ตฌ์ฑ ์์ ์์ฑ์ ํด๋์ค๋ฅผ ์ ๊ณตํ์ญ์์ค.
ํค๋ณด๋ ํฌ์ปค์ค ๋ก์ง์ด ์ฌ๋ฐ๋ฅด๊ฒ ์๋ํ๋ ค๋ฉด ์ฐธ์กฐ๊ฐ ํ์ํฉ๋๋ค.
์ด๋ค ์ ์?
@mh ์ค๊ดํธ๋ฅผ ์ ๊ฑฐํ๋ฉด ์๋ํ์ต๋๋ค.
<Button
component={Link}
to="/customers">
Customers
</Button>
@limakayo ๊ทธ๋ฐ๋ฐ ๋งํฌ๋ฅผ ๋์ ์ผ๋ก ์์ฑํ๊ณ ์ถ์ ๋ ์ด๋ป๊ฒ ํ๋์?
@mh ์ข์ ์ง๋ฌธ, ์ง๊ธ ์ค๊ดํธ๋ก ํ ์คํธํ๋๋ฐ ์๋ํ๋๋ฐ ์ด์ ๋ฅผ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
๋๊ตฌ๋ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์์ต๋๋ค.
<AppBar
title={"Travel Agency"}
iconElementRight={
<div>
<Link to="/customers" className="navbar"><FlatButton label="Customers" /></Link>
<Link to="/tours" className="navbar"><FlatButton label="Tours" /></Link>
</div>
}
/>
์ฐ๋ฆฌ๋ v1-beta์์ ์ด๋ ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค.
<Button
component={({...props}) => <Link to='/path' {...props} />}
>Path</Button>
๋๋ material-ui๊ฐ ์ฌ์ ํ ์ค๋๋ ์คํ์ผ์ ui ํ๋ ์์ํฌ์ ์ํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ฌ๊ธฐ์์ ์ฐพ์ ๋ชจ๋ ๋ฒํผ ์คํ์ผ์ ์ฐพ์ ์ ์๊ฑฐ๋ ๋จ์ํ ์คํ์ผ์ด ๋๋ฌด ๋ง์ต๋๋ค. ๋๊ตฐ๊ฐ ์ ์ ๊ฐ์ ๋ฎ์ ์์ค์์ ์ฌ์ฉ์ ์ ์ํด์ผ ํ๋ ๊ฒฝ์ฐ ๋ง์นจ๋ด ์ ๋ ๋ง์กฑํฉ๋๋ค. '์คํ์ผ ๊ตฌ์ฑ ์์'๋ CSS, saas ๋ฑ์ ๋ํด ๋ ์ด์ ํ์ํ์ง ์์ผ๋ฉฐ ์์ํ ๊ตฌ์ฑ ์์์ ๋ฐ์ํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค. ๋ฒ๊ทธ๊ฐ ์๋ ๊ฒฝ์ฐ ๋ณ๊ฒฝ ๋ฐฉ๋ฒ ๋๋ ์์น๋ฅผ ํ์ ํ๋ ค๊ณ ๋ง์ ์๊ฐ, ์ผ, ์๊ฐ์ ๋ญ๋นํ์ต๋๋ค. ํฅํ ์ถ์ ..
@palaniichukdmytro ๋ ์๋ฃจ์ ์ ๊ฐ์ฌํ์ง๋ง BottomNavigationAction์ ๋ฆฌํ ์คํ์ผ์ ๊นจ๋จ๋ฆฝ๋๋ค.
์ด๊ฒ์ material-ui ๋ฒํผ์์ ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค.
```
'react'์์ React ๊ฐ์ ธ์ค๊ธฐ
'@material-ui/core/Button'์์ ๋ฒํผ ๊ฐ์ ธ์ค๊ธฐ
'react-router-dom'์์ { ๋งํฌ } ๊ฐ์ ธ์ค๊ธฐ
const ์ ์ถ ๋ฒํผ = () =>
์ ํ = "์ ์ถ"
์ ์ฒด ๋์ด
๋ณํ = "ํฌํจ"
์์ = "๊ธฐ๋ณธ"
๊ตฌ์ฑ์์={๋งํฌ}
to="/form"
>
์์ ์ ์ถ
์๋ ์ฝ๋๋ฅผ ์ฌ์ฉํ์ฌ Link๋ก ๋ฒํผ์ ๋ ๋๋งํ๋ ค๊ณ ์๋ํ์ง๋ง ๋ทฐ์ ์๋ฌด ๊ฒ๋ ๋ ๋๋ง๋์ง ์์ต๋๋ค.
<Button
component={() => (
<Link
to={{
pathname: 'hello-there',
state: {
hello: 'HELLO THERE!',
},
}}
/>
)}
size="small"
variant="contained"
color="primary"
fullWidth={true}
>
HELLO BUTTON
</Button>
material-ui๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ ๊ฒฝ๋ก๋ก ์ํ์ ์ ๋ฌํ ์ ์๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น?
๊ตฌ์ฑ ์์={() =>(
~์={{
๊ฒฝ๋ก ์ด๋ฆ: '์๋ ํ์ธ์',
์ํ: {
์๋ ํ์ธ์: '์๋ ํ์ธ์!',
},
}}
/>
)}
ํฌ๊ธฐ="์์"
๋ณํ = "ํฌํจ"
์์ = "๊ธฐ๋ณธ"
์ ์ฒด ๋๋น={true}
>
์๋ ํ์ธ์ ๋ฒํผ
๊ฐ์ ์ง๋ฌธ์ด ์์ต๋๋ค. ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์ด ์์ต๋๊น?
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@mariusk ๋น์ ์ ์ง๊ธ ์ด๊ฒ์ ํ ์ ์์ด์ผ ํฉ๋๋ค: