我有一个问题,如何彻底配置路由器,因为我认为这是不对的。在拥有一个在/
之后呈现所有内容的应用程序之前(/ login,/ register,/ dashboard等),但是在向其添加了一个客户之后,从服务器启动该应用程序后,我们仅收到空白页。 (示例/登录,示例/注册等)
基本上,我认为原因是因为Web服务器不为前端应用程序提供服务,但是当它提供服务时,它无法识别路径。
const tenantBase = (window.location.pathname.split('/'))[1];
console.log(tenantBase)
class App extends Component {
constructor(props) {
super(props);
this.state = {
globalClientNumber: Auth.customerId,
};
}
render() {
return (
<div className='switchContainer'>
<Switch>
<Route exact={true} path={`/${tenantBase}/`} component={Login} />
<Route exact={true} path={`/${tenantBase}/login`} component={Login} />
<Route exact={true} path={`/${tenantBase}/register`} component={Register} />
<Route exact={true} path={`/${tenantBase}/change_password`} component={CPassword} />
<PrivateRoute path={`/${tenantBase}/dashboard`} component={Dashboard} />
</Switch>
</div>
);
}
}
//Private router function
const PrivateRoute = ({ component: Component, ...rest }) => {
return (
<Route
{...rest}
render={props =>
Auth.isAuthenticated === true && Auth.customerId !== '' ? (
<Component {...props} />
) : (
<Redirect
to={{ pathname: `/${tenantBase}/login`, state: { from: props.location } }}
/>
)}
/>
);
};
export default App;
我已经在互联网上搜索过,看来我必须使用web-pack
,但这是否有必要?我已经使用create-react-app
创建了我的应用程序,因此,如果我需要将其集成到应用程序中,将是一场灾难。