devloco / create-react-wptheme

Create modern, React-enabled WordPress themes with a single command.
MIT License
359 stars 60 forks source link

Router Not Working #67

Open Spectrevuln-sketch opened 2 years ago

Spectrevuln-sketch commented 2 years ago

i have some project and i wanna build wp theme with create-react wptheme but route is not working i already follow some tutorial in http://michaelsoriano.com/wordpress-theme-react-part-2-routes-context/ but router still not working this my code below

import React from 'react'
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import Archive from './templates/Archive';
import Single from './templates/Single';

const Routes = () => {
    return (

        <Router>
            <Switch>
                <Route exact path="/" component={Archive} />
                <Route path="/page" component={Single} />
            </Switch>
        </Router>
    )
}

export default Routes

in the single page

import React from 'react'

const Single = (props) => {
    return (
        <div className="Post">
            PAge Single
        </div>
    )
}

export default Single

i use react-router-dom version 5.3.0

WeamAdel commented 2 years ago

It did not work for me either, maybe you should consider using the new router API, this worked for me.

PeterHaughie commented 1 year ago

Can you give an example? We're trying to bring this project up to React Router Dom v6 and the Context.js is proving hard to pin down.