0

I am trying to send querystring parameters to another page using history object in the button click event like as below

const viewChange = (record) => {
debugger;
history.push('/Viewchange?id=record.id&dataid=record.dataid');
};

and this is route where i have defined in routes.js file

{
  path: '/Viewchange/:id/:dataid',
  exact: true,
  title: 'Viewchange',
  icon: 'dashboard',
  breadcrumbs: ['dashboard'],
  contentComponent: ViewChangeRequest,
  isEnabled: () => false,
},

some how i am getting an empty page with url below

http://localhost:3000/Viewchange?id=record.id&dataid=record.dataid#

I am not sure where i am doing wrong in this case, Could any one please let me know how to attach querystring values to url the below code is the component which i am going to redirect

 const ViewChangeRequest = (props) => {
  };
  export default withRouter(ViewChangeRequest);

many thanks in advance

complete route.js code

   [
    {
      path: '/',
      exact: true,
      title: 'Dashboard',
      icon: 'dashboard',
      breadcrumbs: ['Dashboard'],
      contentComponent: UserDashboard,
      isEnabled: () => true,
    },
    {
      type: 'subMenu',
      title: 'Codes and Guidelines',
      children: [
        {
          path: '/LocalCodes',
          exact: true,
          title: 'Local Codes',
          icon: 'dashboard',
          breadcrumbs: ['Codes and Guidelines', 'Local Codes'],
          contentComponent: AddLocalCode,
          isEnabled: () => true,
        },
      ],
    },
    {
      type: 'subMenu',
      title: 'Design Criteria',
      children: [
        {
          path: '/Climate',
          exact: true,
          title: 'Climate',
          icon: 'dashboard',
          breadcrumbs: ['Design Criteria', 'Climate'],
          contentComponent: ContentClimate,
          isEnabled: () => true,
        },
      ],
    },
    {
      path: '/Viewchange/:id/:dataid',
      title: 'Viewchange',
      icon: 'dashboard',
      breadcrumbs: ['dashboard'],
      contentComponent: ViewChangeRequest,
      isEnabled: () => false,
    },
  ];

2 Answers 2

1

You need to use backtick character (template literals) to dynamically construct your url.

history.push(`/Viewchange?id=${record.id}&dataid=${record.dataid}`);
Sign up to request clarification or add additional context in comments.

4 Comments

it is redirecting to the page but it is giving blank page with the url like this http://localhost:3000/Viewchange?id=34daf76e9e6043238bd1725a347af8d4&dataid=96a83572aec2425a8e8ee75afbf52bd3#
@EnigmaState it is related with your route definitions. Can you add your react-router-dom route definitions?
@EnigmaState is this a configuration file for your routes? How do you use it? Can you add to the question?
0

There are two ways to construct dynamic Urls:

  1. Using Strings - history.push('/Viewchange?id=' + record.id + '&dataid=' + record.dataid);
  2. Using Bactick -
history.push(`/Viewchange?id=${record.id}&dataid=${record.dataid}`);

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.