defaultPath property added to Router

This commit is contained in:
NikolaBorislavovHristov 2019-04-19 17:03:03 +03:00
parent 3ec8c5afc7
commit 45c985f299
4 changed files with 55 additions and 47 deletions

View file

@ -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 = () => (
<React.StrictMode>
<Router
className={styles['router']}
viewsConfig={routerViewsConfig}
defaultPath={defaultPath}
viewsConfig={viewsConfig}
/>
</React.StrictMode>
);

47
src/App/routerConfig.js Normal file
View file

@ -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;

View file

@ -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;

View file

@ -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;