Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get to the specific product route #20

Closed
samsur opened this issue Sep 2, 2016 · 2 comments
Closed

Unable to get to the specific product route #20

samsur opened this issue Sep 2, 2016 · 2 comments

Comments

@samsur
Copy link

samsur commented Sep 2, 2016

I can think of a common use case where you email a link to a specific product to someone

Example : http://localhost:3000/product/1

When I type this route on the browser address bar, I am seeing a bunch of console error, including "System is not defined".
Tried hosting this on IIS with the rewrite rule in web.config as follows and it does work only for links like
http://localhost:3000/products

 <system.webServer>
 <rewrite>
      <rules>
        <rule name="ClientRouting" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
          </conditions>
          <action type="Rewrite" url="index.html" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

How to create a rule so that the proper component is loaded. - Thanks

@DeborahK
Copy link
Owner

DeborahK commented Sep 2, 2016

There are two ways to specify client-side routes:

  • HTML 5 style URLS
  • Hash style URLs

By default, Angular 2 uses the HTML 5 style URLs, which mean that the server needs to be configured to support them, as you have shown above. Here is a post with a suggested web.config http://stackoverflow.com/questions/12614072/how-do-i-configure-iis-for-url-rewriting-an-angularjs-application-in-html5-mode (The post is for Angular 1, but the server side info is the same.)

It may be easier to instead use Hash style URLs. If you are using the new router and the RC5+ modules, you can specify hash style URLs as follows:

export const appRoutingModule: ModuleWithProviders =
              RouterModule.forRoot(appRoutes, { useHash: true});

@DeborahK DeborahK closed this as completed Sep 2, 2016
@samsur
Copy link
Author

samsur commented Sep 2, 2016

Thanks Deborah. This was very useful information and solved my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants