Skip to content

Is it possible for build/index.html to function in browser without the need of a server (double click from file location) ? #3030

@varvarasd

Description

@varvarasd

Hi everyone,

I'm struggling to find the solution to this issue I'm having with create-react-app. After running npm build I want to be able to open the index.html from build folder, in browser with 'doubleclick' from file location, without the need of npm or any server. I also want my routes and functionality of the app to work in this scenario, basically to have my client see the app without having to use any server. I've been doing some research on the matter but couldn't find much. I would like to know if it's possible and if anyone has any links or even solutions to share in case I'm missing something.
I'm rather new to react and your help will mean a lot.
I'm using ubuntu 17. My route in App.js looks like so :

class App extends React.Component {
  render(){
    return(
      <Router basename="/">
        <Switch>
            <Route exact path="/" component={LoginComponent}/>
            <Route path="/app" component={AppLayout}/>
        </Switch>
      </Router>
    );
  }
}

then my index.js looks like so:

ReactDOM.render(<App />, document.getElementById('root'));

After running npm run build and open build/index.html in browser it shows nothing. After inspecting I can see the <div id="root"> being there but displaying only the comment <!-- react-empty: 1 -->.

Any help would be greatly appreciated
Many thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions