You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
249 lines
5.9 KiB
249 lines
5.9 KiB
import React, { Component } from "react"; |
|
import "./App.css"; |
|
import { |
|
BrowserRouter as Router, |
|
Route, |
|
Switch, |
|
Redirect, |
|
} from "react-router-dom"; |
|
import { connect } from "react-redux"; |
|
import { user } from "~/Redux/actions"; |
|
|
|
import proxy from "./Redux/proxy"; |
|
import Home from "./views/Home/index"; |
|
import Faq from "./views/Faq/index"; |
|
import Contact from "./views/Contact/index"; |
|
import About from "./views/About/index"; |
|
import Products from "./views/Products/index"; |
|
import Product from "./views/Product/index"; |
|
import QR from "./views/QR/index"; |
|
import Auth from "./views/Auth/index"; |
|
import QRScan from "./views/QRScan/index"; |
|
import Activation from "./views/Activation/index"; |
|
import ChatList from "./views/ChatList/index"; |
|
import Chatroom from "./views/ChatRoom/index"; |
|
import Cart from "./views/Cart/index"; |
|
import MyBooks from "./views/MyBooks/index"; |
|
import AR from "./views/AR/index"; |
|
|
|
class AppRouter extends Component { |
|
constructor(props) { |
|
super(props); |
|
window.router = this; |
|
} |
|
|
|
state = {}; |
|
|
|
componentDidMount() { |
|
if (this.props.profile) { |
|
return; |
|
} else { |
|
this.props.getProfile(); |
|
} |
|
} |
|
|
|
render() { |
|
let home = ( |
|
<Route exact path={"/"}> |
|
{proxy.status() ? ( |
|
this.props.profile ? ( |
|
<Home /> |
|
) : ( |
|
<Auth page={"profile"} /> |
|
) |
|
) : ( |
|
<Auth /> |
|
)} |
|
</Route> |
|
); |
|
|
|
return ( |
|
<Router> |
|
<Switch> |
|
{home} |
|
<Route exact path={"/faq"}> |
|
{proxy.status() ? ( |
|
<Faq /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/contact"}> |
|
{proxy.status() ? ( |
|
<Contact /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/about"}> |
|
{proxy.status() ? ( |
|
<About /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/products"}> |
|
{proxy.status() ? ( |
|
<Products /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/products/:id"}> |
|
{proxy.status() ? ( |
|
<Product /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/qr"}> |
|
{proxy.status() ? ( |
|
<QR /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/auth"}> |
|
<Auth /> |
|
</Route> |
|
<Route exact path={"/profile"}> |
|
<Auth page={"profile"} /> |
|
</Route> |
|
<Route exact path={"/qr-scan"}> |
|
{proxy.status() ? ( |
|
<QRScan /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
|
|
<Route exact path={"/activation"}> |
|
{proxy.status() ? ( |
|
<Activation /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/chatroom"}> |
|
{proxy.status() ? ( |
|
<Chatroom /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/cart"}> |
|
{proxy.status() ? ( |
|
<Cart /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/mybooks"}> |
|
{proxy.status() ? ( |
|
<MyBooks /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
<Route exact path={"/ar"}> |
|
{proxy.status() ? ( |
|
<AR /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
{window.innerWidth < 1000 ? ( |
|
<Route exact path={"/chatroom/:id"}> |
|
{proxy.status() ? ( |
|
<Chatroom /> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
) : null} |
|
<Route path={""}> |
|
{proxy.status() ? ( |
|
<Redirect |
|
to={{ |
|
pathname: "/qr", |
|
search: |
|
"?id=" + |
|
window.location.pathname.slice( |
|
window.location.pathname.lastIndexOf("/") + 1, |
|
window.location.pathname.length |
|
), |
|
}} |
|
/> |
|
) : ( |
|
<Redirect |
|
to={{ |
|
pathname: "/auth", |
|
}} |
|
/> |
|
)} |
|
</Route> |
|
</Switch> |
|
</Router> |
|
); |
|
} |
|
} |
|
|
|
export default connect( |
|
(state) => ({ |
|
profile: state.user.status, |
|
// status: state.user.status, |
|
}), |
|
{ getProfile: user.getProfile } |
|
)(AppRouter);
|
|
|