0
  1. i build a page "user dashboard" and added shortcode [aft_wp_user_dashboard]

below code is inside plugins main file

    function aft_wp_user_dashboard() { 
        return "<div id='aft_wp_user_dashboard'>User Dashboard</div>"; 
    }

    add_shortcode('aft_wp_user_dashboard', 'aft_wp_user_dashboard');
  1. opening http://localhost/user-dashboard, i get this on inspect

    <div id='aft_wp_user_dashboard'></div>
    
  2. i render react project for id='aft_wp_user_dashboard' and react project renders here

     function Index() {
     return (
         <BrowserRouter basename="/user-dashboard">
             <Suspense fallback={<div>Loading...</div>}>
                 <Routes>
                     <Route exact path="/" element={<UserDashboard />} />
                     <Route exact path="/product" element={<Product />} />
                 </Routes>
             </Suspense>
         </BrowserRouter>
     )
    

    }

     document.addEventListener('DOMContentLoaded', () => {
     var root_id = "aft_wp_user_dashboard"
     if ('undefined' !== typeof document.getElementById(root_id) && null !== 
          document.getElementById(root_id)) {
          ReactDOM.render(<Index />, document.getElementById(root_id));
     }
    

    } );

  3. Main and Product Link(react-router-dom) works fine and component render

     function UserDashboard() {
     return (
         <div>
             <Link to="/">Main</Link>
             <Link to="/product">Product</Link>
         </div>
     )
     }
    
  4. problem is, when i refresh page http://localhost/user-dashboard/product, 404 page is given.

Have anyone faced this issue.

Note: I cannot use this solution React routing in wordpress and have changed wp permalink settings to post name.

1 Answer 1

0

As i am unable to find proper solution for link routing, i solved this via conditional component rendering.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.