简体   繁体   中英

preact-router with default case not working as intended

I am new to preact and I am trying to develop a project with Preact-X.

I want my project to run with default URL with only one component.

for ex: loaclhost:8080 , localhost:8080/jobs , localhost:8080/?some-parameters .

I have a component like below:

import { h } from 'preact'
import { Provider } from 'react-redux'
import { Router } from 'preact-router'
import Jobs from './jobs/index'

function App({ store }) {
    function handleRoute(e) {
        console.log(e.url)
    }

    return (
        <Provider store={store}>
            <Router onChange={handleRoute}>
                <Jobs default />
            </Router>
        </Provider>
    )
}

export default App

I am not sure why it works only for localhost:8080 but not other routes.

You can find the whole repo here

Any help would be appreciated.

you need to set Webpack's devServer.historyApiFallback option to true.

On line 64 of your configuration:

devServer: {
  historyApiFallback: true,
  // etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM