From 45c985f299f150befd01cf60c08868ad12b419e7 Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Fri, 19 Apr 2019 17:03:03 +0300 Subject: [PATCH] defaultPath property added to Router --- src/App/App.js | 5 ++-- src/App/routerConfig.js | 47 +++++++++++++++++++++++++++++++++ src/App/routerViewsConfig.js | 44 ------------------------------ src/navigation/Router/Router.js | 6 ++++- 4 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 src/App/routerConfig.js delete mode 100644 src/App/routerViewsConfig.js diff --git a/src/App/App.js b/src/App/App.js index b08c46306..8a16c5da9 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -1,13 +1,14 @@ const React = require('react'); const { Router } = require('stremio-navigation'); -const routerViewsConfig = require('./routerViewsConfig'); +const { defaultPath, views: viewsConfig } = require('./routerConfig'); const styles = require('./styles'); const App = () => ( ); diff --git a/src/App/routerConfig.js b/src/App/routerConfig.js new file mode 100644 index 000000000..78a5be27c --- /dev/null +++ b/src/App/routerConfig.js @@ -0,0 +1,47 @@ +const { Addons, Board, Calendar, Detail, Discover, Intro, Library, Player, Search, Settings } = require('stremio-routes'); + +const routerConfig = { + defaultPath: '/', + views: [ + [ + { + path: '/', + component: Board + }, + { + path: '/intro', + component: Intro + }, + { + path: '/calendar', + component: Calendar + }, + { + path: '/discover/:type?/:sort?/:genre?', + component: Discover + } + ], + [ + { + path: '/addons', + component: Addons + }, + { + path: '/settings', + component: Settings + }, + { + path: '/detail', + component: Detail + } + ], + [ + { + path: '/player', + component: Player + } + ] + ] +}; + +module.exports = routerConfig; diff --git a/src/App/routerViewsConfig.js b/src/App/routerViewsConfig.js deleted file mode 100644 index 08212b7cb..000000000 --- a/src/App/routerViewsConfig.js +++ /dev/null @@ -1,44 +0,0 @@ -const { Calendar, Discover, Addons, Settings, Board, Player, Detail, Intro } = require('stremio-routes'); - -const routerViewsConfig = [ - [ - { - path: '/', - component: Board - }, - { - path: '/intro', - component: Intro - }, - { - path: '/calendar', - component: Calendar - }, - { - path: '/discover/:type?/:sort?/:genre?', - component: Discover - } - ], - [ - { - path: '/addons', - component: Addons - }, - { - path: '/settings', - component: Settings - }, - { - path: '/detail', - component: Detail - } - ], - [ - { - path: '/player', - component: Player - } - ] -]; - -module.exports = routerViewsConfig; diff --git a/src/navigation/Router/Router.js b/src/navigation/Router/Router.js index 9e73cfa5b..5a1cf282a 100644 --- a/src/navigation/Router/Router.js +++ b/src/navigation/Router/Router.js @@ -89,7 +89,7 @@ class Router extends React.Component { } } - window.location.replace('#/'); + window.location.replace(`#${this.props.defaultPath}`); } render() { @@ -109,11 +109,15 @@ class Router extends React.Component { Router.propTypes = { className: PropTypes.string, + defaultPath: PropTypes.string.isRequired, viewsConfig: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.exact({ path: PropTypes.string.isRequired, component: PropTypes.elementType.isRequired, options: PropTypes.object }))).isRequired }; +Router.defaultProps = { + defaultPath: '/' +}; module.exports = Router;