How to save bad invalid URLs that were typed in?











up vote
0
down vote

favorite












I am having a react-redux app and react-router v4 inside of app



Is there a way to catch all invalid URLs that were entered and save them to an array, like so ['https://mysite.co/progects', 'https://mysite.co/sometypo', 'https://mysite.co/something']?



And then I want to send that data to server for building some redirects and some sitemap



Currently I have this:



 <Switch>
{/* <Route path='/blog' exact component={Blog} /> */}
<Route path='/projects/:id' component={ProjectDetails} />
<Route path='/career/:id' component={CareerDetails} />
<Route path='/apply-for-job' render={(props) => (
<ModalWindow
{...props}
modalHeader='Apply form'>
<ApplyForm history={props.history} />
</ModalWindow>
)} />
<Route exact path='/' component={withScrollPreservation(LandingPage)} />
<Route component={NoMatch} />
{/* <Route component={withScrollPreservation(LandingPage)} /> */}
</Switch>









share|improve this question


























    up vote
    0
    down vote

    favorite












    I am having a react-redux app and react-router v4 inside of app



    Is there a way to catch all invalid URLs that were entered and save them to an array, like so ['https://mysite.co/progects', 'https://mysite.co/sometypo', 'https://mysite.co/something']?



    And then I want to send that data to server for building some redirects and some sitemap



    Currently I have this:



     <Switch>
    {/* <Route path='/blog' exact component={Blog} /> */}
    <Route path='/projects/:id' component={ProjectDetails} />
    <Route path='/career/:id' component={CareerDetails} />
    <Route path='/apply-for-job' render={(props) => (
    <ModalWindow
    {...props}
    modalHeader='Apply form'>
    <ApplyForm history={props.history} />
    </ModalWindow>
    )} />
    <Route exact path='/' component={withScrollPreservation(LandingPage)} />
    <Route component={NoMatch} />
    {/* <Route component={withScrollPreservation(LandingPage)} /> */}
    </Switch>









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am having a react-redux app and react-router v4 inside of app



      Is there a way to catch all invalid URLs that were entered and save them to an array, like so ['https://mysite.co/progects', 'https://mysite.co/sometypo', 'https://mysite.co/something']?



      And then I want to send that data to server for building some redirects and some sitemap



      Currently I have this:



       <Switch>
      {/* <Route path='/blog' exact component={Blog} /> */}
      <Route path='/projects/:id' component={ProjectDetails} />
      <Route path='/career/:id' component={CareerDetails} />
      <Route path='/apply-for-job' render={(props) => (
      <ModalWindow
      {...props}
      modalHeader='Apply form'>
      <ApplyForm history={props.history} />
      </ModalWindow>
      )} />
      <Route exact path='/' component={withScrollPreservation(LandingPage)} />
      <Route component={NoMatch} />
      {/* <Route component={withScrollPreservation(LandingPage)} /> */}
      </Switch>









      share|improve this question













      I am having a react-redux app and react-router v4 inside of app



      Is there a way to catch all invalid URLs that were entered and save them to an array, like so ['https://mysite.co/progects', 'https://mysite.co/sometypo', 'https://mysite.co/something']?



      And then I want to send that data to server for building some redirects and some sitemap



      Currently I have this:



       <Switch>
      {/* <Route path='/blog' exact component={Blog} /> */}
      <Route path='/projects/:id' component={ProjectDetails} />
      <Route path='/career/:id' component={CareerDetails} />
      <Route path='/apply-for-job' render={(props) => (
      <ModalWindow
      {...props}
      modalHeader='Apply form'>
      <ApplyForm history={props.history} />
      </ModalWindow>
      )} />
      <Route exact path='/' component={withScrollPreservation(LandingPage)} />
      <Route component={NoMatch} />
      {/* <Route component={withScrollPreservation(LandingPage)} /> */}
      </Switch>






      reactjs redirect react-router sitemap






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 11:09









      Rostyslav Skyba

      45




      45
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          In your NoMatch component, you can have the logic to update unmatched/incorrect urls



          class NoMatch extends React.Component {
          componentDidMount() {
          const { addNoMatchUrl } = this.props;
          // you might want to handle the duplicate url logic here too in addNoMatchUrl method
          addNoMatchUrl(this.props.location.pathname);
          }
          componentDidUpdate(prevProps) {
          const { location, addNoMatchUrl } = this.props;
          if (location.pathname !== prevProps.location.pathname) {
          addNoMatchUrl(location.pathname);
          }
          }
          render() {
          // render logic
          }
          }

          export default connect(null, {addNoMatchUrl});





          share|improve this answer




























            up vote
            0
            down vote













            If you want, say, to redirect someone, who typed '/progects' to '/projects' - well, that's nice UX, but your Switch block will be cluttered with tens of possible invalid urls.
            As I see it, maybe you should add <Redirect to='/main' /> at the bottom of your Switch so any invalid url gets redirected to Main component (or whichever you have) or to 404-Component.



            If you still want to gather them, then instead of redirecting to Main or 404 Component, send them to specific Error component, where you can get the link via this.props.history.location and handle that link further in the component: send to server, set that url in local/session storage, etc.



            Note that you'll need a way to store that data someplace which won't get cleared on unmounting.



            In order to send users to that route you'll need to place that at the bottom of your Switch.



            <Switch>
            ...{your routes}
            <Route component={Error} />
            </Switch>


            So actually all you need to do is handle those urls in your NoMatch component, like so



            const path = this.props.history.location;
            axios.post('your api', path);





            share|improve this answer























              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',
              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%2f53391695%2fhow-to-save-bad-invalid-urls-that-were-typed-in%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              In your NoMatch component, you can have the logic to update unmatched/incorrect urls



              class NoMatch extends React.Component {
              componentDidMount() {
              const { addNoMatchUrl } = this.props;
              // you might want to handle the duplicate url logic here too in addNoMatchUrl method
              addNoMatchUrl(this.props.location.pathname);
              }
              componentDidUpdate(prevProps) {
              const { location, addNoMatchUrl } = this.props;
              if (location.pathname !== prevProps.location.pathname) {
              addNoMatchUrl(location.pathname);
              }
              }
              render() {
              // render logic
              }
              }

              export default connect(null, {addNoMatchUrl});





              share|improve this answer

























                up vote
                0
                down vote













                In your NoMatch component, you can have the logic to update unmatched/incorrect urls



                class NoMatch extends React.Component {
                componentDidMount() {
                const { addNoMatchUrl } = this.props;
                // you might want to handle the duplicate url logic here too in addNoMatchUrl method
                addNoMatchUrl(this.props.location.pathname);
                }
                componentDidUpdate(prevProps) {
                const { location, addNoMatchUrl } = this.props;
                if (location.pathname !== prevProps.location.pathname) {
                addNoMatchUrl(location.pathname);
                }
                }
                render() {
                // render logic
                }
                }

                export default connect(null, {addNoMatchUrl});





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  In your NoMatch component, you can have the logic to update unmatched/incorrect urls



                  class NoMatch extends React.Component {
                  componentDidMount() {
                  const { addNoMatchUrl } = this.props;
                  // you might want to handle the duplicate url logic here too in addNoMatchUrl method
                  addNoMatchUrl(this.props.location.pathname);
                  }
                  componentDidUpdate(prevProps) {
                  const { location, addNoMatchUrl } = this.props;
                  if (location.pathname !== prevProps.location.pathname) {
                  addNoMatchUrl(location.pathname);
                  }
                  }
                  render() {
                  // render logic
                  }
                  }

                  export default connect(null, {addNoMatchUrl});





                  share|improve this answer












                  In your NoMatch component, you can have the logic to update unmatched/incorrect urls



                  class NoMatch extends React.Component {
                  componentDidMount() {
                  const { addNoMatchUrl } = this.props;
                  // you might want to handle the duplicate url logic here too in addNoMatchUrl method
                  addNoMatchUrl(this.props.location.pathname);
                  }
                  componentDidUpdate(prevProps) {
                  const { location, addNoMatchUrl } = this.props;
                  if (location.pathname !== prevProps.location.pathname) {
                  addNoMatchUrl(location.pathname);
                  }
                  }
                  render() {
                  // render logic
                  }
                  }

                  export default connect(null, {addNoMatchUrl});






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 12:09









                  Shubham Khatri

                  76.9k1490126




                  76.9k1490126
























                      up vote
                      0
                      down vote













                      If you want, say, to redirect someone, who typed '/progects' to '/projects' - well, that's nice UX, but your Switch block will be cluttered with tens of possible invalid urls.
                      As I see it, maybe you should add <Redirect to='/main' /> at the bottom of your Switch so any invalid url gets redirected to Main component (or whichever you have) or to 404-Component.



                      If you still want to gather them, then instead of redirecting to Main or 404 Component, send them to specific Error component, where you can get the link via this.props.history.location and handle that link further in the component: send to server, set that url in local/session storage, etc.



                      Note that you'll need a way to store that data someplace which won't get cleared on unmounting.



                      In order to send users to that route you'll need to place that at the bottom of your Switch.



                      <Switch>
                      ...{your routes}
                      <Route component={Error} />
                      </Switch>


                      So actually all you need to do is handle those urls in your NoMatch component, like so



                      const path = this.props.history.location;
                      axios.post('your api', path);





                      share|improve this answer



























                        up vote
                        0
                        down vote













                        If you want, say, to redirect someone, who typed '/progects' to '/projects' - well, that's nice UX, but your Switch block will be cluttered with tens of possible invalid urls.
                        As I see it, maybe you should add <Redirect to='/main' /> at the bottom of your Switch so any invalid url gets redirected to Main component (or whichever you have) or to 404-Component.



                        If you still want to gather them, then instead of redirecting to Main or 404 Component, send them to specific Error component, where you can get the link via this.props.history.location and handle that link further in the component: send to server, set that url in local/session storage, etc.



                        Note that you'll need a way to store that data someplace which won't get cleared on unmounting.



                        In order to send users to that route you'll need to place that at the bottom of your Switch.



                        <Switch>
                        ...{your routes}
                        <Route component={Error} />
                        </Switch>


                        So actually all you need to do is handle those urls in your NoMatch component, like so



                        const path = this.props.history.location;
                        axios.post('your api', path);





                        share|improve this answer

























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          If you want, say, to redirect someone, who typed '/progects' to '/projects' - well, that's nice UX, but your Switch block will be cluttered with tens of possible invalid urls.
                          As I see it, maybe you should add <Redirect to='/main' /> at the bottom of your Switch so any invalid url gets redirected to Main component (or whichever you have) or to 404-Component.



                          If you still want to gather them, then instead of redirecting to Main or 404 Component, send them to specific Error component, where you can get the link via this.props.history.location and handle that link further in the component: send to server, set that url in local/session storage, etc.



                          Note that you'll need a way to store that data someplace which won't get cleared on unmounting.



                          In order to send users to that route you'll need to place that at the bottom of your Switch.



                          <Switch>
                          ...{your routes}
                          <Route component={Error} />
                          </Switch>


                          So actually all you need to do is handle those urls in your NoMatch component, like so



                          const path = this.props.history.location;
                          axios.post('your api', path);





                          share|improve this answer














                          If you want, say, to redirect someone, who typed '/progects' to '/projects' - well, that's nice UX, but your Switch block will be cluttered with tens of possible invalid urls.
                          As I see it, maybe you should add <Redirect to='/main' /> at the bottom of your Switch so any invalid url gets redirected to Main component (or whichever you have) or to 404-Component.



                          If you still want to gather them, then instead of redirecting to Main or 404 Component, send them to specific Error component, where you can get the link via this.props.history.location and handle that link further in the component: send to server, set that url in local/session storage, etc.



                          Note that you'll need a way to store that data someplace which won't get cleared on unmounting.



                          In order to send users to that route you'll need to place that at the bottom of your Switch.



                          <Switch>
                          ...{your routes}
                          <Route component={Error} />
                          </Switch>


                          So actually all you need to do is handle those urls in your NoMatch component, like so



                          const path = this.props.history.location;
                          axios.post('your api', path);






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 20 at 12:10

























                          answered Nov 20 at 11:50









                          Nikita Neganov

                          184




                          184






























                              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.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • 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%2f53391695%2fhow-to-save-bad-invalid-urls-that-were-typed-in%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

                              404 Error Contact Form 7 ajax form submitting

                              How to know if a Active Directory user can login interactively

                              TypeError: fit_transform() missing 1 required positional argument: 'X'