how to check if url param entered exist in location.pathname via ReactHow to check empty/undefined/null string in JavaScript?How do I check if an element is hidden in jQuery?How do I check if an array includes an object in JavaScript?How can I know which radio button is selected via jQuery?How do I modify the URL without reloading the page?Checking if a key exists in a JavaScript object?How to check whether a string contains a substring in JavaScript?How to check for “undefined” in JavaScript?How to check if an object is an array?JavaScript check if variable exists (is defined/initialized)

Drawing ramified coverings with tikz

Two-sided logarithm inequality

Indicating multiple different modes of speech (fantasy language or telepathy)

Did arcade monitors have same pixel aspect ratio as TV sets?

A social experiment. What is the worst that can happen?

How to decide convergence of Integrals

What major Native American tribes were around Santa Fe during the late 1850s?

Have I saved too much for retirement so far?

Is a model fitted to data or is data fitted to a model?

My friend sent me a screenshot of a transaction hash, but when I search for it I find divergent data. What happened?

Why do IPv6 unique local addresses have to have a /48 prefix?

Open a doc from terminal, but not by its name

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

anything or something to eat

Will the technology I first learn determine the direction of my future career?

How much character growth crosses the line into breaking the character

Diode in opposite direction?

Are lightweight LN wallets vulnerable to transaction withholding?

We have a love-hate relationship

Engineer refusing to file/disclose patents

Should I stop contributing to retirement accounts?

Why does the Sun have different day lengths, but not the gas giants?

Has Darkwing Duck ever met Scrooge McDuck?

How do I implement a file system driver driver in Linux?



how to check if url param entered exist in location.pathname via React


How to check empty/undefined/null string in JavaScript?How do I check if an element is hidden in jQuery?How do I check if an array includes an object in JavaScript?How can I know which radio button is selected via jQuery?How do I modify the URL without reloading the page?Checking if a key exists in a JavaScript object?How to check whether a string contains a substring in JavaScript?How to check for “undefined” in JavaScript?How to check if an object is an array?JavaScript check if variable exists (is defined/initialized)













0















Well, I try to understand legacy code with React routes onboard.



I have an url like



/home/reports/some_report_numbers


when user changes the ulr like that:



/home/reports/some_report_numb


I want to check if "some_report_numb" exists in props, in this.props.location.pathname. If exists - fine, go that way, otherwise go another way.



Maybe it is a wrong approach at all? Well, when the report is shown and user just deletes some letters in url I need to redirect to /home/ page. To do that I need somehow to check if that report with that numbers exists at all.



Maybe it could be done via



<Route name=SomeRouteName path='reports/:reportId' component=HomePage />









share|improve this question


























    0















    Well, I try to understand legacy code with React routes onboard.



    I have an url like



    /home/reports/some_report_numbers


    when user changes the ulr like that:



    /home/reports/some_report_numb


    I want to check if "some_report_numb" exists in props, in this.props.location.pathname. If exists - fine, go that way, otherwise go another way.



    Maybe it is a wrong approach at all? Well, when the report is shown and user just deletes some letters in url I need to redirect to /home/ page. To do that I need somehow to check if that report with that numbers exists at all.



    Maybe it could be done via



    <Route name=SomeRouteName path='reports/:reportId' component=HomePage />









    share|improve this question
























      0












      0








      0








      Well, I try to understand legacy code with React routes onboard.



      I have an url like



      /home/reports/some_report_numbers


      when user changes the ulr like that:



      /home/reports/some_report_numb


      I want to check if "some_report_numb" exists in props, in this.props.location.pathname. If exists - fine, go that way, otherwise go another way.



      Maybe it is a wrong approach at all? Well, when the report is shown and user just deletes some letters in url I need to redirect to /home/ page. To do that I need somehow to check if that report with that numbers exists at all.



      Maybe it could be done via



      <Route name=SomeRouteName path='reports/:reportId' component=HomePage />









      share|improve this question














      Well, I try to understand legacy code with React routes onboard.



      I have an url like



      /home/reports/some_report_numbers


      when user changes the ulr like that:



      /home/reports/some_report_numb


      I want to check if "some_report_numb" exists in props, in this.props.location.pathname. If exists - fine, go that way, otherwise go another way.



      Maybe it is a wrong approach at all? Well, when the report is shown and user just deletes some letters in url I need to redirect to /home/ page. To do that I need somehow to check if that report with that numbers exists at all.



      Maybe it could be done via



      <Route name=SomeRouteName path='reports/:reportId' component=HomePage />






      javascript reactjs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 9:02









      ValerianTiValerianTi

      167




      167






















          1 Answer
          1






          active

          oldest

          votes


















          0














          According to the documentation of react-router-dom



          Link: https://reacttraining.com/react-router/web/example/url-params



          match become an object that can be used in your component. Like explain in the documentation, you have access to match object with the following steps:




          • Route component as this.props.match


          • Route render as ( match ) => ()


          • Route children as ( match ) => ()


          • withRouter as this.props.match


          • matchPath as the return value

          For example, if you have the following route:



          <Route path="/reports/:reportId" component=HomePage />


          In your component, you can access to this with: this.props.match because it's an object and inside it, you will have what you want.



          After that, you could check what params you have in your URL.



          Now, if you want to redirect the user, you can use <Redirect to='/your/path' />






          share|improve this answer























          • Thank you for answer. I've tried it, but console.log(this.props.match); returned me undefined

            – ValerianTi
            Mar 7 at 10:12












          • Have you connected your component with the withRouter ?

            – Anthony Brancato
            Mar 7 at 10:19











          • I have import withRouter from "react-router"; in my Router.js and render: function() { const match = this.props; Anything else needed?

            – ValerianTi
            Mar 7 at 10:32












          • So, if we take your code from the beginning, with <Route /> And if you want to triggered params in your URL, the documentation uses match like this : function Topics( match ) You can now use it as a props. I don't know if I am clear, this is my first time on stackoverflow This is the Source reacttraining.com/react-router/web/example/basic

            – Anthony Brancato
            Mar 7 at 10:56











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55039790%2fhow-to-check-if-url-param-entered-exist-in-location-pathname-via-react%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          According to the documentation of react-router-dom



          Link: https://reacttraining.com/react-router/web/example/url-params



          match become an object that can be used in your component. Like explain in the documentation, you have access to match object with the following steps:




          • Route component as this.props.match


          • Route render as ( match ) => ()


          • Route children as ( match ) => ()


          • withRouter as this.props.match


          • matchPath as the return value

          For example, if you have the following route:



          <Route path="/reports/:reportId" component=HomePage />


          In your component, you can access to this with: this.props.match because it's an object and inside it, you will have what you want.



          After that, you could check what params you have in your URL.



          Now, if you want to redirect the user, you can use <Redirect to='/your/path' />






          share|improve this answer























          • Thank you for answer. I've tried it, but console.log(this.props.match); returned me undefined

            – ValerianTi
            Mar 7 at 10:12












          • Have you connected your component with the withRouter ?

            – Anthony Brancato
            Mar 7 at 10:19











          • I have import withRouter from "react-router"; in my Router.js and render: function() { const match = this.props; Anything else needed?

            – ValerianTi
            Mar 7 at 10:32












          • So, if we take your code from the beginning, with <Route /> And if you want to triggered params in your URL, the documentation uses match like this : function Topics( match ) You can now use it as a props. I don't know if I am clear, this is my first time on stackoverflow This is the Source reacttraining.com/react-router/web/example/basic

            – Anthony Brancato
            Mar 7 at 10:56
















          0














          According to the documentation of react-router-dom



          Link: https://reacttraining.com/react-router/web/example/url-params



          match become an object that can be used in your component. Like explain in the documentation, you have access to match object with the following steps:




          • Route component as this.props.match


          • Route render as ( match ) => ()


          • Route children as ( match ) => ()


          • withRouter as this.props.match


          • matchPath as the return value

          For example, if you have the following route:



          <Route path="/reports/:reportId" component=HomePage />


          In your component, you can access to this with: this.props.match because it's an object and inside it, you will have what you want.



          After that, you could check what params you have in your URL.



          Now, if you want to redirect the user, you can use <Redirect to='/your/path' />






          share|improve this answer























          • Thank you for answer. I've tried it, but console.log(this.props.match); returned me undefined

            – ValerianTi
            Mar 7 at 10:12












          • Have you connected your component with the withRouter ?

            – Anthony Brancato
            Mar 7 at 10:19











          • I have import withRouter from "react-router"; in my Router.js and render: function() { const match = this.props; Anything else needed?

            – ValerianTi
            Mar 7 at 10:32












          • So, if we take your code from the beginning, with <Route /> And if you want to triggered params in your URL, the documentation uses match like this : function Topics( match ) You can now use it as a props. I don't know if I am clear, this is my first time on stackoverflow This is the Source reacttraining.com/react-router/web/example/basic

            – Anthony Brancato
            Mar 7 at 10:56














          0












          0








          0







          According to the documentation of react-router-dom



          Link: https://reacttraining.com/react-router/web/example/url-params



          match become an object that can be used in your component. Like explain in the documentation, you have access to match object with the following steps:




          • Route component as this.props.match


          • Route render as ( match ) => ()


          • Route children as ( match ) => ()


          • withRouter as this.props.match


          • matchPath as the return value

          For example, if you have the following route:



          <Route path="/reports/:reportId" component=HomePage />


          In your component, you can access to this with: this.props.match because it's an object and inside it, you will have what you want.



          After that, you could check what params you have in your URL.



          Now, if you want to redirect the user, you can use <Redirect to='/your/path' />






          share|improve this answer













          According to the documentation of react-router-dom



          Link: https://reacttraining.com/react-router/web/example/url-params



          match become an object that can be used in your component. Like explain in the documentation, you have access to match object with the following steps:




          • Route component as this.props.match


          • Route render as ( match ) => ()


          • Route children as ( match ) => ()


          • withRouter as this.props.match


          • matchPath as the return value

          For example, if you have the following route:



          <Route path="/reports/:reportId" component=HomePage />


          In your component, you can access to this with: this.props.match because it's an object and inside it, you will have what you want.



          After that, you could check what params you have in your URL.



          Now, if you want to redirect the user, you can use <Redirect to='/your/path' />







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 10:05









          Anthony BrancatoAnthony Brancato

          112




          112












          • Thank you for answer. I've tried it, but console.log(this.props.match); returned me undefined

            – ValerianTi
            Mar 7 at 10:12












          • Have you connected your component with the withRouter ?

            – Anthony Brancato
            Mar 7 at 10:19











          • I have import withRouter from "react-router"; in my Router.js and render: function() { const match = this.props; Anything else needed?

            – ValerianTi
            Mar 7 at 10:32












          • So, if we take your code from the beginning, with <Route /> And if you want to triggered params in your URL, the documentation uses match like this : function Topics( match ) You can now use it as a props. I don't know if I am clear, this is my first time on stackoverflow This is the Source reacttraining.com/react-router/web/example/basic

            – Anthony Brancato
            Mar 7 at 10:56


















          • Thank you for answer. I've tried it, but console.log(this.props.match); returned me undefined

            – ValerianTi
            Mar 7 at 10:12












          • Have you connected your component with the withRouter ?

            – Anthony Brancato
            Mar 7 at 10:19











          • I have import withRouter from "react-router"; in my Router.js and render: function() { const match = this.props; Anything else needed?

            – ValerianTi
            Mar 7 at 10:32












          • So, if we take your code from the beginning, with <Route /> And if you want to triggered params in your URL, the documentation uses match like this : function Topics( match ) You can now use it as a props. I don't know if I am clear, this is my first time on stackoverflow This is the Source reacttraining.com/react-router/web/example/basic

            – Anthony Brancato
            Mar 7 at 10:56

















          Thank you for answer. I've tried it, but console.log(this.props.match); returned me undefined

          – ValerianTi
          Mar 7 at 10:12






          Thank you for answer. I've tried it, but console.log(this.props.match); returned me undefined

          – ValerianTi
          Mar 7 at 10:12














          Have you connected your component with the withRouter ?

          – Anthony Brancato
          Mar 7 at 10:19





          Have you connected your component with the withRouter ?

          – Anthony Brancato
          Mar 7 at 10:19













          I have import withRouter from "react-router"; in my Router.js and render: function() { const match = this.props; Anything else needed?

          – ValerianTi
          Mar 7 at 10:32






          I have import withRouter from "react-router"; in my Router.js and render: function() { const match = this.props; Anything else needed?

          – ValerianTi
          Mar 7 at 10:32














          So, if we take your code from the beginning, with <Route /> And if you want to triggered params in your URL, the documentation uses match like this : function Topics( match ) You can now use it as a props. I don't know if I am clear, this is my first time on stackoverflow This is the Source reacttraining.com/react-router/web/example/basic

          – Anthony Brancato
          Mar 7 at 10:56






          So, if we take your code from the beginning, with <Route /> And if you want to triggered params in your URL, the documentation uses match like this : function Topics( match ) You can now use it as a props. I don't know if I am clear, this is my first time on stackoverflow This is the Source reacttraining.com/react-router/web/example/basic

          – Anthony Brancato
          Mar 7 at 10:56




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55039790%2fhow-to-check-if-url-param-entered-exist-in-location-pathname-via-react%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович