Giter VIP home page Giter VIP logo

Comments (12)

meeroslav avatar meeroslav commented on August 20, 2024 1

@brunorentcars please create a separate issue for this and I'll get on to it asap. Thanks!

from localize-router.

meeroslav avatar meeroslav commented on August 20, 2024 1

@dahfazz
Short answer: - you need to prefix base routes with backslash

['/users' | localize]

Long answer:
Router (and it's directives) work in a fashion that even if you skip providing the backslash (sign that it's a base route) if your link is defined on top level component (component without it's own routes) it will not consider it a relative sub route. However, localize-router doesn't have deep knowledge/access to full routing mechanism, thus cannot distinguish this. The only way for localize-router to know which route is base one (to preprend url with language) is by reading backslash as a first character in the url.

from localize-router.

meeroslav avatar meeroslav commented on August 20, 2024

Hi @Masquer, it might be that documentation is a bit misleading. Thanks for pointing that out. Documentation only explains the algorithm by which language gets chosen.

Localize-router prepends all the routes with selected language and creates a redirect to base language url e.g. my/route/path will become en/my/route/path. Once localize-router had been initialized it overrides the initial routes, so route my/route/path no longer exists in RouterConfig and Router therefore returns 404. This is not defect, it's by design as above mentioned route is invalid.

There are two approaches to solve your request:

  • By catching 404 and redirecting to {localize.parser.currentLang}/{location.path} manually in project
  • By handling this in localize-router

Please note that at the moment this has low prio against lazy loading, and most likely will not be implemented any time soon.

from localize-router.

brunosalgado avatar brunosalgado commented on August 20, 2024

how can I add catching exception in router?

from localize-router.

meeroslav avatar meeroslav commented on August 20, 2024

@brunorentcars If you refer to catching 404 you can do it by pointing all unknown routes (**) to the component that will handle the redirection.

https://angular.io/docs/ts/latest/guide/router.html

If this is not what you're referring to, then please provide more information.

from localize-router.

brunosalgado avatar brunosalgado commented on August 20, 2024

if I set a different language on URI there isn't on configuration file(locales.json) my application crashes.

There routers for 404:
{path: '404', component: NotFoundComponent},
{path: '**', redirectTo: '404'}

But localize-router put this routers inside children language route.
For example:
{path: '', redirectTo: 'en', pathMatch: 'full'}
{path: 'en', children: [
{path: '404', component: NotFoundComponent},
{path: '**', redirectTo: '404'}
]}

from localize-router.

juanmcampos avatar juanmcampos commented on August 20, 2024

hello @brunorentcars just wondering if you managed to accomplish this behavior? Thnx

from localize-router.

brunosalgado avatar brunosalgado commented on August 20, 2024

@juanmcampos check this issue: #22

from localize-router.

juanmcampos avatar juanmcampos commented on August 20, 2024

@brunorentcars great! thnx I updated my module version, and was able to get that '**' wilcard route. But any clue on how do I get the requested url? so i can handle the translate? any help would be awesome really thnx

from localize-router.

brunosalgado avatar brunosalgado commented on August 20, 2024

@juanmcampos if you want to get the current route path, you can use ActivatedRoute.
For example:
constructor(private activatedRoute:ActivatedRoute) {
console.log(this.activatedRoute.snapshot.url)
}

If you want to get the full uri, you can use Router.
For example:
constructor(private router:Router) {
console.log(this.router.url)
}

from localize-router.

dahfazz avatar dahfazz commented on August 20, 2024

Hi @meeroslav

I'm dealing with a similar issue; On load everything is OK.
I'm on ***/en/home

There, I click on a link on which i put [routerLink]=['users' | localize]

It throws an error because /users doesn't exist anymore, and I should target /en/users

I thought it was exactly why I need to use localize Pipe.

What am I missing please ?

from localize-router.

meeroslav avatar meeroslav commented on August 20, 2024

Closing as this will not be implemented.

from localize-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.