How to bundle a React app to a subdirectory on a server?

前端 未结 10 2154
名媛妹妹
名媛妹妹 2020-12-04 14:41

I have a React app I\'ve been developing on my localhost. I want to copy it to a server into a subdirectory called vensa.

My webpack config file looks like this..

10条回答
  •  我在风中等你
    2020-12-04 15:34

    I had to do something similar recently in order to get a react app running in a sub directory. Try the below and see how you get on.

    import React from 'react';
    import { Router, Route, IndexRoute, useRouterHistory  } from 'react-router';
    import { createHistory } from 'history';
    import VensaDashboard from './components/VensaDashboard';
    import Inbox from './components/Inbox';
    import Todo from './components/Todo';
    import Home from './components/Home';
    
    // specify basename below if running in a subdirectory or set as "/" if app runs in root
    const appHistory = useRouterHistory(createHistory)({
      basename: "/vensa"
    });
    
    export default (
      
        
          
          
          
        
      
    );
    

    You may also have to update the path to your bundle.js file in index.html as shown below

    
    
    
      Vensa Development Test
      
    
    
      

提交回复
热议问题