React router consume my url request to back-end API










0















I'm building an SPA react-redux app at client-side, asp.net core back-end API.
Everythings run perfectly with IISExpress when debugging.
But when I deploy to IIS as a web application nested default website with the alias "mysubdomain". Everything still runs ok except export function.



(1st case): Open browser, enter download API link: http://localhost/mysubdomain/api/v1/export?filterparam. A save dialogue open. That was my expectation.



(2nd case: normal case): open my site (homepage): http://localhost/mysubdomain then click export, a new window open by the link:
http://localhost/mysubdomain/api/v1/export?filterparam.
I was expecting that savefile popup opening similar to (1st case) but NO. Browse return my components/Layout rendered.



I don't know what happening with react router/route? Or I make something wrong? I guess that react-router just consume my URL-request then render my Component, instead of call to my back-end API.



My export function inside redux store:



export: (filterParams) => async (dispatch, getState) => 
const url = `api/v1/export?$filterParams`;
window.open(url,'_blank');



Back-end API:



[HttpGet]
[Route("download")]
public async Task<IActionResult> Download(DailyDischargeUrlQuery urlQuery)

var stream = await _dailyDischargeRepository.ExportAsCsvStream(urlQuery.DischargeDate, urlQuery.MRN, urlQuery.GetCompanies(), urlQuery.GetOrders());

return File(stream, "text/csv", "dailydischarge.csv");



index.js



const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href');
const history = createBrowserHistory( basename: baseUrl );
const initialState = window.initialReduxState;
const store = configureStore(history, initialState);
const rootElement = document.getElementById('root');

ReactDOM.render(
<Provider store=store>
<ConnectedRouter history=history>
<App />
</ConnectedRouter>
</Provider>,
rootElement);

registerServiceWorker();


App.js



import 'core-js';
import React from 'react';
import Route, Router from 'react-router';
import Layout from './components/Layout';
import Home from './components/Home';

export default () => (
<Layout>
<Route exact path='/' component=Home/>
</Layout>
);









share|improve this question




























    0















    I'm building an SPA react-redux app at client-side, asp.net core back-end API.
    Everythings run perfectly with IISExpress when debugging.
    But when I deploy to IIS as a web application nested default website with the alias "mysubdomain". Everything still runs ok except export function.



    (1st case): Open browser, enter download API link: http://localhost/mysubdomain/api/v1/export?filterparam. A save dialogue open. That was my expectation.



    (2nd case: normal case): open my site (homepage): http://localhost/mysubdomain then click export, a new window open by the link:
    http://localhost/mysubdomain/api/v1/export?filterparam.
    I was expecting that savefile popup opening similar to (1st case) but NO. Browse return my components/Layout rendered.



    I don't know what happening with react router/route? Or I make something wrong? I guess that react-router just consume my URL-request then render my Component, instead of call to my back-end API.



    My export function inside redux store:



    export: (filterParams) => async (dispatch, getState) => 
    const url = `api/v1/export?$filterParams`;
    window.open(url,'_blank');



    Back-end API:



    [HttpGet]
    [Route("download")]
    public async Task<IActionResult> Download(DailyDischargeUrlQuery urlQuery)

    var stream = await _dailyDischargeRepository.ExportAsCsvStream(urlQuery.DischargeDate, urlQuery.MRN, urlQuery.GetCompanies(), urlQuery.GetOrders());

    return File(stream, "text/csv", "dailydischarge.csv");



    index.js



    const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href');
    const history = createBrowserHistory( basename: baseUrl );
    const initialState = window.initialReduxState;
    const store = configureStore(history, initialState);
    const rootElement = document.getElementById('root');

    ReactDOM.render(
    <Provider store=store>
    <ConnectedRouter history=history>
    <App />
    </ConnectedRouter>
    </Provider>,
    rootElement);

    registerServiceWorker();


    App.js



    import 'core-js';
    import React from 'react';
    import Route, Router from 'react-router';
    import Layout from './components/Layout';
    import Home from './components/Home';

    export default () => (
    <Layout>
    <Route exact path='/' component=Home/>
    </Layout>
    );









    share|improve this question


























      0












      0








      0








      I'm building an SPA react-redux app at client-side, asp.net core back-end API.
      Everythings run perfectly with IISExpress when debugging.
      But when I deploy to IIS as a web application nested default website with the alias "mysubdomain". Everything still runs ok except export function.



      (1st case): Open browser, enter download API link: http://localhost/mysubdomain/api/v1/export?filterparam. A save dialogue open. That was my expectation.



      (2nd case: normal case): open my site (homepage): http://localhost/mysubdomain then click export, a new window open by the link:
      http://localhost/mysubdomain/api/v1/export?filterparam.
      I was expecting that savefile popup opening similar to (1st case) but NO. Browse return my components/Layout rendered.



      I don't know what happening with react router/route? Or I make something wrong? I guess that react-router just consume my URL-request then render my Component, instead of call to my back-end API.



      My export function inside redux store:



      export: (filterParams) => async (dispatch, getState) => 
      const url = `api/v1/export?$filterParams`;
      window.open(url,'_blank');



      Back-end API:



      [HttpGet]
      [Route("download")]
      public async Task<IActionResult> Download(DailyDischargeUrlQuery urlQuery)

      var stream = await _dailyDischargeRepository.ExportAsCsvStream(urlQuery.DischargeDate, urlQuery.MRN, urlQuery.GetCompanies(), urlQuery.GetOrders());

      return File(stream, "text/csv", "dailydischarge.csv");



      index.js



      const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href');
      const history = createBrowserHistory( basename: baseUrl );
      const initialState = window.initialReduxState;
      const store = configureStore(history, initialState);
      const rootElement = document.getElementById('root');

      ReactDOM.render(
      <Provider store=store>
      <ConnectedRouter history=history>
      <App />
      </ConnectedRouter>
      </Provider>,
      rootElement);

      registerServiceWorker();


      App.js



      import 'core-js';
      import React from 'react';
      import Route, Router from 'react-router';
      import Layout from './components/Layout';
      import Home from './components/Home';

      export default () => (
      <Layout>
      <Route exact path='/' component=Home/>
      </Layout>
      );









      share|improve this question
















      I'm building an SPA react-redux app at client-side, asp.net core back-end API.
      Everythings run perfectly with IISExpress when debugging.
      But when I deploy to IIS as a web application nested default website with the alias "mysubdomain". Everything still runs ok except export function.



      (1st case): Open browser, enter download API link: http://localhost/mysubdomain/api/v1/export?filterparam. A save dialogue open. That was my expectation.



      (2nd case: normal case): open my site (homepage): http://localhost/mysubdomain then click export, a new window open by the link:
      http://localhost/mysubdomain/api/v1/export?filterparam.
      I was expecting that savefile popup opening similar to (1st case) but NO. Browse return my components/Layout rendered.



      I don't know what happening with react router/route? Or I make something wrong? I guess that react-router just consume my URL-request then render my Component, instead of call to my back-end API.



      My export function inside redux store:



      export: (filterParams) => async (dispatch, getState) => 
      const url = `api/v1/export?$filterParams`;
      window.open(url,'_blank');



      Back-end API:



      [HttpGet]
      [Route("download")]
      public async Task<IActionResult> Download(DailyDischargeUrlQuery urlQuery)

      var stream = await _dailyDischargeRepository.ExportAsCsvStream(urlQuery.DischargeDate, urlQuery.MRN, urlQuery.GetCompanies(), urlQuery.GetOrders());

      return File(stream, "text/csv", "dailydischarge.csv");



      index.js



      const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href');
      const history = createBrowserHistory( basename: baseUrl );
      const initialState = window.initialReduxState;
      const store = configureStore(history, initialState);
      const rootElement = document.getElementById('root');

      ReactDOM.render(
      <Provider store=store>
      <ConnectedRouter history=history>
      <App />
      </ConnectedRouter>
      </Provider>,
      rootElement);

      registerServiceWorker();


      App.js



      import 'core-js';
      import React from 'react';
      import Route, Router from 'react-router';
      import Layout from './components/Layout';
      import Home from './components/Home';

      export default () => (
      <Layout>
      <Route exact path='/' component=Home/>
      </Layout>
      );






      reactjs rest api iis asp.net-core






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 10:11







      nmDat

















      asked Nov 16 '18 at 9:44









      nmDatnmDat

      12017




      12017






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The problem has been resolved!
          That because of service worker built-in create-react-app.



          // In production, we register a service worker to serve assets from local cache.

          // This lets the app load faster on subsequent visits in production, and gives
          // it offline capabilities. However, it also means that developers (and users)
          // will only see deployed updates on the "N+1" visit to a page, since previously
          // cached resources are updated in the background.





          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%2f53335156%2freact-router-consume-my-url-request-to-back-end-api%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














            The problem has been resolved!
            That because of service worker built-in create-react-app.



            // In production, we register a service worker to serve assets from local cache.

            // This lets the app load faster on subsequent visits in production, and gives
            // it offline capabilities. However, it also means that developers (and users)
            // will only see deployed updates on the "N+1" visit to a page, since previously
            // cached resources are updated in the background.





            share|improve this answer



























              0














              The problem has been resolved!
              That because of service worker built-in create-react-app.



              // In production, we register a service worker to serve assets from local cache.

              // This lets the app load faster on subsequent visits in production, and gives
              // it offline capabilities. However, it also means that developers (and users)
              // will only see deployed updates on the "N+1" visit to a page, since previously
              // cached resources are updated in the background.





              share|improve this answer

























                0












                0








                0







                The problem has been resolved!
                That because of service worker built-in create-react-app.



                // In production, we register a service worker to serve assets from local cache.

                // This lets the app load faster on subsequent visits in production, and gives
                // it offline capabilities. However, it also means that developers (and users)
                // will only see deployed updates on the "N+1" visit to a page, since previously
                // cached resources are updated in the background.





                share|improve this answer













                The problem has been resolved!
                That because of service worker built-in create-react-app.



                // In production, we register a service worker to serve assets from local cache.

                // This lets the app load faster on subsequent visits in production, and gives
                // it offline capabilities. However, it also means that developers (and users)
                // will only see deployed updates on the "N+1" visit to a page, since previously
                // cached resources are updated in the background.






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 7:21









                nmDatnmDat

                12017




                12017





























                    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%2f53335156%2freact-router-consume-my-url-request-to-back-end-api%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

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    政党

                    天津地下鉄3号線