[go: nahoru, domu]

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

How to do a "redirect" #12

Closed
LeonLiuY opened this issue Apr 22, 2016 · 2 comments
Closed

How to do a "redirect" #12

LeonLiuY opened this issue Apr 22, 2016 · 2 comments

Comments

@LeonLiuY
Copy link

When I open the root page /#!/, I want to redirect to the Home page /#!/home, and change the hash.

I could render the home page correctly by adding this in location2action

calse list of
  [ "home" ] ->
    [ ShowPage Home ]

  [ "" ] ->
    [ ShowPage Home ]

But it won't change the URL.

Then how to make a "redirect"?

@rgrempel
Copy link
Owner

I suppose you could fall back on the History module and use History.setPath, History.replacePath or possibly History.setHash (in the latest version), depending on whether you want to generate a history entry or not.

That is, the location2action for "" would not show the page directly ... instead, it would return a different action that would use one of the History methods (as an effect) to set the URL you want. That, in turn, would trigger a second round of location2action, which would now be for "home", which you'd handle normally.

At least, I think that sort of thing ought to work -- I haven't tried it lately.

The other possible approach would be to do something with deltaToUpdate that returns a HashUpdate to the desired URL. However, I have a feeling that might not work, because I think I disabled deltaToUpdate while processing the actions returned by location2action ... I was getting some infinite loops otherwise.

@LeonLiuY
Copy link
Author

Thanks @rgrempel !

I have succeeded:

type Action 
  = ...
  | Redirect String
  | NoOp

location2action list = 
  case list of
    [ "" ] ->
      [ Redirect "home"]

update action model =
  case action of

    Redirect url ->
      ( model, History.replacePath (prefix ++ url) |> Task.map (\()-> NoOp) |> Effects.task)

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