How to save bad invalid URLs that were typed in?












0















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



























    0















    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

























      0












      0








      0








      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 '18 at 11:09









      Rostyslav SkybaRostyslav Skyba

      45




      45
























          2 Answers
          2






          active

          oldest

          votes


















          0














          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































            0














            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',
              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%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









              0














              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




























                0














                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


























                  0












                  0








                  0







                  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 '18 at 12:09









                  Shubham KhatriShubham Khatri

                  80.7k1597137




                  80.7k1597137

























                      0














                      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






























                        0














                        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




























                          0












                          0








                          0







                          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 '18 at 12:10

























                          answered Nov 20 '18 at 11:50









                          Nikita NeganovNikita Neganov

                          1336




                          1336






























                              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%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

                              MongoDB - Not Authorized To Execute Command

                              How to fix TextFormField cause rebuild widget in Flutter

                              in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith