Answer the question
In order to leave comments, you need to log in
How to build React Router so that mobile and desktop apps have different screens?
The application is built into two files: mobile.js and desktop.js. For the most part, they differ in screenshots, while the routes should always match, hence the question: how to organize the routes file so that the routes are the same for both versions of the application, while the screenshots are imported from different mobile/desktop folders?
PS routes are connected separately to the file with the desktop version and mobile.
import React from 'react';
import { BrowserRouter, Switch, Route, Redirect } from 'react-router-dom';
import Welcome from 'screens/mobile/Welcome';
import Login from 'screens/mobile/Login';
import LoginCode from 'screens/mobile/LoginCode';
import ProfileEdit from 'screens/mobile/ProfileEdit';
import Dialogs from 'screens/mobile/Dialogs';
export default (
<BrowserRouter>
<Switch>
<Route path="/verify" component={LoginCode} />
<Route path="/welcome" component={Welcome} />
<Route path="/profile" component={ProfileEdit} />
<Route path="/im" component={Dialogs} />
<Route path="/login" component={Login} />
</Switch>
</BrowserRouter>
);
Answer the question
In order to leave comments, you need to log in
In component, set the value depending on the environment variable.
For example, build:
in webpack config (example for old webpack):
plugins: [
new webpack.DefinePlugin({
'ENV_DEVICE': JSON.stringify(process.env.ENV_DEVICE), // вытаскиваем переменную
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question