All files / nexshop-web-contents/src/component contents-router.js

100% Statements 18/18
100% Branches 2/2
100% Functions 4/4
100% Lines 18/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 523x 3x           3x 3x 3x 3x 3x 3x 3x 3x 3x       1x 1x         12x 12x   12x                                 3x 2x          
import React, {Component} from 'react';
import {
    Redirect,
    Switch,
    Route,
    withRouter
} from 'react-router-dom';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import ContentsMain from './contents-main';
import Playlist from './playlist/playlist';
import PlaylistPreview from './preview/playlist/playlist-preview';
import {closeFloatingView} from '../action/floating-view';
import ContentsPreview from "./preview/contents/contents-preview";
import Scene from "./scene/scene";
import ScenePreview from "./preview/scene/scene-preview";
 
class ContentsRouter extends Component {
    componentDidMount() {
        this.props.history.listen(() => {
            this.props.actions.closeFloatingView();
        });
    }
 
    render() {
        const url = this.props.match.url;
        const redirectUrl = url.lastIndexOf('/') === url.length - 1 ? url.substr(0, url.length -1): url;
 
        return (
            <div>
                <Switch>
                    <Route path={`${url}/main`} component={ContentsMain}/>
                    <Route path={`${url}/create-playlist`} component={Playlist}/>
                    <Route path={`${url}/playlist-detail`} component={Playlist}/>
                    <Route path={`${url}/playlist-preview`} component={PlaylistPreview}/>
                    <Route path={`${url}/contents-preview`} component={ContentsPreview}/>
                    <Route path={`${url}/scene`} component={Scene}/>
                    <Route path={`${url}/scene-preview`} component={ScenePreview}/>
                    <Redirect exact from={`${url}`} to={`${redirectUrl}/main`} />
                </Switch>
            </div>
        )
    }
}
 
const mapDispatchToProps = (dispatch) => {
    return {
        actions: bindActionCreators({closeFloatingView}, dispatch)
    }
};
 
export default withRouter(connect(null, mapDispatchToProps)(ContentsRouter));